From 478a2a31478ccdca1dc4472ba39ceea6c0feed70 Mon Sep 17 00:00:00 2001 From: rahulramesha <71900764+rahulramesha@users.noreply.github.com> Date: Tue, 17 Aug 2021 16:24:46 +0530 Subject: [PATCH] adding check for base64 (#6532) --- app/client/src/workers/validations.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/client/src/workers/validations.ts b/app/client/src/workers/validations.ts index 4b5d9c211e..b466dfb781 100644 --- a/app/client/src/workers/validations.ts +++ b/app/client/src/workers/validations.ts @@ -11,11 +11,9 @@ import _, { isObject, isPlainObject, isString, - startsWith, toString, uniq, } from "lodash"; -import { WidgetProps } from "../widgets/BaseWidget"; import moment from "moment"; import { ValidationConfig } from "constants/PropertyControlConstants"; @@ -657,6 +655,7 @@ export const VALIDATORS: Record = { parsed: config.params?.default || "", message: `${WIDGET_TYPE_VALIDATION_ERROR}: ${getExpectedType(config)}`, }; + const base64Regex = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; const base64ImageRegex = /^data:image\/.*;base64/; const imageUrlRegex = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpeg|jpg|gif|png)??(?:&?[^=&]*=[^=&]*)*/; if ( @@ -677,7 +676,7 @@ export const VALIDATORS: Record = { parsed: value, }; } - if (btoa(atob(value)) === value) { + if (base64Regex.test(value) && btoa(atob(value)) === value) { return { isValid: true, parsed: `data:image/png;base64,${value}` }; } }