Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set options from decorator to IsBase64 method #2383

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/decorator/string/IsBase64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
Expand Down
9 changes: 9 additions & 0 deletions test/functional/validation-functions-and-decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ describe('IsBase32', () => {

describe('IsBase64', () => {
const constraint = '';
const urlNotSafe = [btoa('malicious_data+/=')];
const validValues = ['aGVsbG8='];
const invalidValues = [null, undefined, 'hell*mynameisalex'];

Expand All @@ -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';
Expand Down