isURL(): Allow URLs to have only a username in the userinfo subcomponent#1644
Merged
profnandaa merged 2 commits intovalidatorjs:masterfrom Apr 17, 2021
Merged
isURL(): Allow URLs to have only a username in the userinfo subcomponent#1644profnandaa merged 2 commits intovalidatorjs:masterfrom
profnandaa merged 2 commits intovalidatorjs:masterfrom
Conversation
The 'userinfo' part of a URL may, according to RFC 1738, contain only a username followed by an '@' sign. The previous behavior of the isURL() function would return false if the userinfo section did not have a colon. In addition to the change in the function, tests have been added to ensure the following exmaples are considered valid: - http://[email protected] - http://user:@example.com - http://user:[email protected] The following are considered not valid: - http://@example.com - http://:@example.com - http://:example.com As a practical example, Sentry (https://github.com/getsentry/sentry) uses a format like http://[email protected]/10 for it's DSNs (which are just URLs).
Codecov Report
@@ Coverage Diff @@
## master #1644 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 100 100
Lines 1843 1845 +2
=========================================
+ Hits 1843 1845 +2
Continue to review full report at Codecov.
|
tux-tn
approved these changes
Apr 16, 2021
Member
tux-tn
left a comment
There was a problem hiding this comment.
LGTM 🎉 !
Nice catch and thank you for adding the missing options!
profnandaa
approved these changes
Apr 17, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses issue #1643
The
isURL()function doesn't accept URLs that have a userinfo subcomponent without a colon. For example, all of these examples should be accpeted:http://[email protected]http://user:@example.comhttp://user:[email protected]However, currently, 1) is not accepted.
This PR fixes the
isURL()function and adds several tests to define and validate the behavior.In addition to the code and tests, I added some missing options to the
isURL()section of the README (my editor also removed some trailing whitespace from a few other lines).Checklist