-
Notifications
You must be signed in to change notification settings - Fork 52
PM-971 Allow hyphen in url - asset library #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -58,7 +58,7 @@ | |||
/** | |||
* regex for url validation | |||
*/ | |||
const urlRegex = /((https?):\/\/)?(www.)?[a-z0-9]+(\.[a-z]{2,}){1,3}(#?\/?(?:[a-zA-Z0-9#]+))*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/ | |||
const urlRegex = /((https?):\/\/)?(www\.)?[\w-]+(\.[a-z]{2,}){1,3}(#?\/?(?:[a-zA-Z0-9#-]+))*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
To fix the problem, we need to remove the ambiguity in the regular expression that can cause exponential backtracking. Specifically, we should modify the part [a-zA-Z0-9#-]+
to ensure that the character #
is not matched in multiple ways. We can achieve this by using a more specific character class or by restructuring the regular expression to avoid ambiguous matches.
The best way to fix this without changing existing functionality is to replace [a-zA-Z0-9#-]+
with a more precise pattern that avoids ambiguity. For example, we can use [\w-]+
to match word characters and hyphens, and handle the #
character separately if needed.
-
Copy modified line R61
@@ -60,3 +60,3 @@ | ||
*/ | ||
const urlRegex = /((https?):\/\/)?(www\.)?[\w-]+(\.[a-z]{2,}){1,3}(#?\/?(?:[a-zA-Z0-9#-]+))*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/ | ||
const urlRegex = /((https?):\/\/)?(www\.)?[\w-]+(\.[a-z]{2,}){1,3}(#?\/?(?:[\w-]+))*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/ | ||
|
…ression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me. It's FE code. if someone wants to "hack" the regex, good for them, they'll block their browser window. no need to spend more time on this if it fixed the ticket iisue.
What's in this PR?
Changes the regex to allow hyphen in url in the form to add new links for Asset Library