Browse Source

allow addresses to have surrounding whitespace in validation

patch-2
Manuel Araoz 10 years ago
parent
commit
e331c4ea49
  1. 1
      lib/address.js
  2. 13
      test/address.js

1
lib/address.js

@ -276,6 +276,7 @@ Address._transformString = function(data, network, type) {
if (typeof(data) !== 'string') {
throw new TypeError('data parameter supplied is not a string.');
}
data = data.trim();
var addressBuffer = Base58Check.decode(data);
var info = Address._transformBuffer(addressBuffer, network, type);
return info;

13
test/address.js

@ -71,7 +71,8 @@ describe('Address', function() {
'15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2',
'1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT',
'1BpbpfLdY7oBS9gK7aDXgvMgr1DPvNhEB2',
'1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7'
'1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7',
' 1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7 \t\n'
];
// livenet p2sh
@ -79,7 +80,8 @@ describe('Address', function() {
'342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey',
'33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk',
'37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3',
'3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy'
'3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy',
'\t \n3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy \r'
];
// testnet p2sh
@ -210,6 +212,13 @@ describe('Address', function() {
should.not.exist(error);
}
});
it('addresses with whitespace are validated correctly', function() {
var ws = ' \r \t \n 1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT \t \n \r';
var error = Address.getValidationError(ws);
should.not.exist(error);
Address.fromString(ws).toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
});
});
describe('instantiation', function() {

Loading…
Cancel
Save