Skip to content

Commit

Permalink
Correct base64 validation. Fixes #1055.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Dec 5, 2016
1 parent 99fd222 commit a959139
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ internals.String = class extends Any {

base64() {

const regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
const regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)$/;

return this._test('base64', regex, function (value, state, options) {

Expand Down
1 change: 1 addition & 0 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,7 @@ describe('string', () => {
['YW', false, null, '"value" must be a valid base64 string'],
['YW==', true],
['YW5', false, null, '"value" must be a valid base64 string'],
['password', false, null, '"value" must be a valid base64 string'],
['YW5=', true],
['$#%#$^$^)(*&^%', false, null, '"value" must be a valid base64 string']
], done);
Expand Down

0 comments on commit a959139

Please sign in to comment.