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: fill base64 options correctly #2549

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions),
},
},
Expand Down
18 changes: 14 additions & 4 deletions test/functional/validation-functions-and-decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1658,17 +1658,27 @@ describe('IsBase64', () => {
const validValues = ['aGVsbG8='];
const invalidValues = [null, undefined, 'hell*mynameisalex'];

const validBase64UrlValues = ['dGVzdA', 'dGV_zdA'];
const invalidBase64UrlValues = [null, undefined, 'dGVzdA=', 'MTIzNDU2Nzg5!!', 'SGVsbG8+V29ybGQ='];

class MyClass {
@IsBase64()
someProperty: string;
}

it('should not fail if validator.validate said that its valid', () => {
return checkValidValues(new MyClass(), validValues);
class MyClassWithConstraint {
@IsBase64({ urlSafe: true })
someProperty: string;
}

it('should not fail if validator.validate said that its valid', async () => {
await checkValidValues(new MyClass(), validValues);
await checkValidValues(new MyClassWithConstraint(), validBase64UrlValues);
});

it('should fail if validator.validate said that its invalid', () => {
return checkInvalidValues(new MyClass(), invalidValues);
it('should fail if validator.validate said that its invalid', async () => {
await checkInvalidValues(new MyClass(), invalidValues);
await checkInvalidValues(new MyClassWithConstraint(), invalidBase64UrlValues);
});

it('should not fail if method in validator said that its valid', () => {
Expand Down