Skip to content

Fix: isURL incorrectly accepts email-like strings (#1674) #2557

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wrknbuycnsmndie
Copy link

Description

This pull request fixes the issue where isURL incorrectly accepted email-like strings such as [email protected] as valid URLs.

Changes:

  • Added a check to detect email-like strings only when no protocol is present.
  • Respected the disallow_auth option to avoid breaking URLs containing authentication info like user:pass@host.

Closes #1674.


✅ All tests passed after the fix.
✅ No breaking changes for authentication URLs.
✅ Code style consistent with the rest of the project.

const emailLikeRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

if (!options || options.disallow_auth !== false) {
if (emailLikeRegex.test(url)) {

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '!@!.' and with many repetitions of '!.'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isURL return true for e-mail
1 participant