Merge pull request #4604 from appsmithorg/fix/4362-recaptcha-field-unexpected-data-types

Fix/4362 recaptcha field unexpected data types
This commit is contained in:
Somangshu Goswami 2021-06-07 14:50:53 +05:30 committed by GitHub
commit e1fb11b27c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,8 +180,25 @@ function RecaptchaComponent(
});
props.onClick && props.onClick(event);
}
// Check if a string is a valid JSON string
const checkValidJson = (inputString: string): boolean => {
try {
JSON.parse(inputString);
return true;
} catch (err) {
return false;
}
};
let validGoogleRecaptchaKey = props.googleRecaptchaKey;
if (validGoogleRecaptchaKey && checkValidJson(validGoogleRecaptchaKey)) {
validGoogleRecaptchaKey = undefined;
}
const status = useScript(
`https://www.google.com/recaptcha/api.js?render=${props.googleRecaptchaKey}`,
`https://www.google.com/recaptcha/api.js?render=${validGoogleRecaptchaKey}`,
);
return (
<div