Created
February 8, 2024 22:39
-
-
Save JonathanGawrych/0bb92a46ca99aed670839feab32f18b9 to your computer and use it in GitHub Desktop.
Ensure that a well-formed url matches a domain and it's subdomains, but don't allow userInfo
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
| // Modified from https://github.com/google/closure-library/blob/7818ff7dc0b53555a7fb3c3427e6761e88bde3a2/closure/goog/uri/utils.js#L189-L208 | |
| new RegExp( | |
| '^' + // Anchor against the entire string. | |
| 'https?:\\/\\/' + // scheme | |
| '(?![^\\\\\\/?#]*@)' + // userInfo disallowed | |
| '(?:(?:[^\\\\\\/?#\\.]+?)\\.)*' + // subdomain | |
| 'mydomain.com' + // domain | |
| '(?::[0-9]+)?' + // port | |
| '(?=[\\\\\\/?#]|$)' // authority-terminating character. | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment