diff --git a/src/decorator/string/IsBase64.ts b/src/decorator/string/IsBase64.ts index 2c5cd3e5be..c59a97009b 100644 --- a/src/decorator/string/IsBase64.ts +++ b/src/decorator/string/IsBase64.ts @@ -26,7 +26,7 @@ export function IsBase64( name: IS_BASE64, constraints: [options], validator: { - validate: (value, args): boolean => isBase64(value), + validate: (value, args): boolean => isBase64(value, options), defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions), }, }, diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index 78ceddcd6d..0d7acc112c 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -1655,6 +1655,7 @@ describe('IsBase32', () => { describe('IsBase64', () => { const constraint = ''; + const urlNotSafe = [btoa('malicious_data+/=')]; const validValues = ['aGVsbG8=']; const invalidValues = [null, undefined, 'hell*mynameisalex']; @@ -1679,6 +1680,14 @@ describe('IsBase64', () => { invalidValues.forEach(value => expect(isBase64(value)).toBeFalsy()); }); + it('should fail if method in validator said that its invalid, and i pass a url not safe and set in options urlSafe to true', () => { + urlNotSafe.forEach(value => expect(isBase64(value, { urlSafe: true })).toBeFalsy()); + }); + + it('should not fail if method in validator said that its valid, and i pass a url not safe and set in options urlSafe to false', () => { + urlNotSafe.forEach(value => expect(isBase64(value, { urlSafe: false })).toBeTruthy()); + }); + it('should return error object with proper data', () => { const validationType = 'isBase64'; const message = 'someProperty must be base64 encoded';