Skip to content

Commit

Permalink
caught bug in validateURL logic that did not meet figma specs for val…
Browse files Browse the repository at this point in the history
…id or invalid URL
  • Loading branch information
corypride committed May 10, 2024
1 parent 730cadd commit 5b36339
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common/utils/helperUtils.ts
Expand Up @@ -281,7 +281,7 @@ export const validateEmail = (email: string | undefined) => {
};

export const validateAgencyURL = (url: string) => {
const urlRegex = /^(?:https?|ftp):\/\/[\w.-]+\.[a-zA-Z]{2,}(?:\/\S*)?$/;
const urlRegex = /^(?:https?|ftp):\/\/(?:[\w.-]+\.)+[a-zA-Z]{2,}(?:\/\S*)?$/;

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'ftp://' and containing many repetitions of '-.'.
return urlRegex.test(url);
};

Expand Down
22 changes: 11 additions & 11 deletions publisher/src/components/Settings/AgencySettingsURL.tsx
Expand Up @@ -62,19 +62,19 @@ const AgencySettingsUrl: React.FC<{
{ message: string } | undefined
>(undefined);
const handleSaveClick = () => {
if (!validateAgencyURL(urlText)) {
setIsURLValid(false);
setErrorMsg({ message: "Invalid Email" });
if (validateAgencyURL(urlText) || urlText === "") {
const updatedSettings = updateAgencySettings(
"HOMEPAGE_URL",
urlText,
parseInt(agencyId)
);
setErrorMsg(undefined);
saveAgencySettings(updatedSettings, agencyId);
removeEditMode();
return;
}
const updatedSettings = updateAgencySettings(
"HOMEPAGE_URL",
urlText,
parseInt(agencyId)
);
setErrorMsg(undefined);
saveAgencySettings(updatedSettings, agencyId);
removeEditMode();
setIsURLValid(false);
setErrorMsg({ message: "Invalid Email" });
};
const handleCancelClick = () => {
if (homepageUrlSetting === urlText) {
Expand Down

0 comments on commit 5b36339

Please sign in to comment.