From ef97e280c7eb2f451e92d9b6e7c3ab9e1a6470e1 Mon Sep 17 00:00:00 2001 From: alenap93 Date: Tue, 16 Jan 2024 16:13:35 +0100 Subject: [PATCH 1/3] fix: set options from decorator to IsBase64 method --- 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 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), }, }, From 33ab553a3b0a3608d6a9fdb3f6cee51fa2ea7cec Mon Sep 17 00:00:00 2001 From: alenap93 Date: Tue, 16 Jan 2024 16:30:36 +0100 Subject: [PATCH 2/3] add test --- .../validation-functions-and-decorators.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index 78ceddcd6d..a3d0549c45 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'; From 8e3dd29c66f7c7c48d0afa0414f260ef9bfc02a2 Mon Sep 17 00:00:00 2001 From: alenap93 Date: Wed, 1 May 2024 12:37:43 +0200 Subject: [PATCH 3/3] fix prettier --- test/functional/validation-functions-and-decorators.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index a3d0549c45..0d7acc112c 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -1655,7 +1655,7 @@ describe('IsBase32', () => { describe('IsBase64', () => { const constraint = ''; - const urlNotSafe = [btoa('malicious_data+/=')] + const urlNotSafe = [btoa('malicious_data+/=')]; const validValues = ['aGVsbG8=']; const invalidValues = [null, undefined, 'hell*mynameisalex'];