From 0c87bebe8b290a2527b8390c4a4877d7412bc2d9 Mon Sep 17 00:00:00 2001 From: AliReza Seyfpour <39882738+aseyfpour@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:30:30 +0330 Subject: [PATCH 1/3] fix: pass IsBase64 options correctly (#2549) * fix: fill base64 options correctly pass the constraint to the isBase64 function add unit test IsBase64 options * refactor: pass options by name --------- Co-authored-by: Brage Sekse Aarset --- src/decorator/string/IsBase64.ts | 2 +- ...validation-functions-and-decorators.spec.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) 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..9f938616c4 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -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', () => { From 3bff66f8eb83f250742fb61ed0fe9c5a0f996ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Fri, 17 Jan 2025 14:01:51 +0100 Subject: [PATCH 2/3] build: disable Dependabot updates --- .github/dependabot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9d58c92e15..8dd39d1739 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,10 +6,10 @@ updates: interval: daily time: "10:00" timezone: Europe/Budapest - open-pull-requests-limit: 5 + open-pull-requests-limit: 0 versioning-strategy: increase commit-message: prefix: build include: scope ignore: - - dependency-name: "husky" \ No newline at end of file + - dependency-name: "husky" From 0ea279bf89f849e12651bfea141837fa28611416 Mon Sep 17 00:00:00 2001 From: Brage Sekse Aarset Date: Fri, 17 Jan 2025 15:29:15 +0200 Subject: [PATCH 3/3] fix: pass arguments correctly to isBase64 (#2574) * fix: update version in package-lock.json * fix: pass options to isBase64 correctly --- src/decorator/string/IsBase64.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decorator/string/IsBase64.ts b/src/decorator/string/IsBase64.ts index c59a97009b..e7002e0e9a 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, options), + validate: (value, args): boolean => isBase64(value, args?.constraints[0]), defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be base64 encoded', validationOptions), }, },