adding check for base64 (#6532)

This commit is contained in:
rahulramesha 2021-08-17 16:24:46 +05:30 committed by GitHub
parent 92f4d878ab
commit 478a2a3147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<ValidationTypes, Validator> = {
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<ValidationTypes, Validator> = {
parsed: value,
};
}
if (btoa(atob(value)) === value) {
if (base64Regex.test(value) && btoa(atob(value)) === value) {
return { isValid: true, parsed: `data:image/png;base64,${value}` };
}
}