GeezerVison is showing github.com — url: improve url.parse() compliance with WHATWG URL · nodejs/node@eb81b6f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/url.js +7-20Lines changed: 7 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,16 +128,6 @@ const { | 128 | 128 | CHAR_LEFT_CURLY_BRACKET, | 129 | 129 | CHAR_RIGHT_CURLY_BRACKET, | 130 | 130 | CHAR_QUESTION_MARK, | 131 | | - CHAR_LOWERCASE_A, | 132 | | - CHAR_LOWERCASE_Z, | 133 | | - CHAR_UPPERCASE_A, | 134 | | - CHAR_UPPERCASE_Z, | 135 | | - CHAR_DOT, | 136 | | - CHAR_0, | 137 | | - CHAR_9, | 138 | | - CHAR_HYPHEN_MINUS, | 139 | | - CHAR_PLUS, | 140 | | - CHAR_UNDERSCORE, | 141 | 131 | CHAR_DOUBLE_QUOTE, | 142 | 132 | CHAR_SINGLE_QUOTE, | 143 | 133 | CHAR_PERCENT, | @@ -147,6 +137,7 @@ const { | 147 | 137 | CHAR_GRAVE_ACCENT, | 148 | 138 | CHAR_VERTICAL_LINE, | 149 | 139 | CHAR_AT, | | 140 | + CHAR_COLON, | 150 | 141 | } = require('internal/constants'); | 151 | 142 |
| 152 | 143 | function urlParse(url, parseQueryString, slashesDenoteHost) { | @@ -514,16 +505,12 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | 514 | 505 | function getHostname(self, rest, hostname) { | 515 | 506 | for (let i = 0; i < hostname.length; ++i) { | 516 | 507 | const code = hostname.charCodeAt(i); | 517 | | - const isValid = (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) || | 518 | | - code === CHAR_DOT || | 519 | | - (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || | 520 | | - (code >= CHAR_0 && code <= CHAR_9) || | 521 | | - code === CHAR_HYPHEN_MINUS || | 522 | | - code === CHAR_PLUS || | 523 | | - code === CHAR_UNDERSCORE || | 524 | | - code > 127; | 525 | | - | 526 | | - // Invalid host character | | 508 | + const isValid = (code !== CHAR_FORWARD_SLASH && | | 509 | + code !== CHAR_BACKWARD_SLASH && | | 510 | + code !== CHAR_HASH && | | 511 | + code !== CHAR_QUESTION_MARK && | | 512 | + code !== CHAR_COLON); | | 513 | + | 527 | 514 | if (!isValid) { | 528 | 515 | self.hostname = hostname.slice(0, i); | 529 | 516 | return `/${hostname.slice(i)}${rest}`; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-url-parse-format.js +21-6Lines changed: 21 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -885,15 +885,15 @@ const parseTests = { | 885 | 885 | protocol: 'https:', | 886 | 886 | slashes: true, | 887 | 887 | auth: null, | 888 | | - host: '', | | 888 | + host: '*', | 889 | 889 | port: null, | 890 | | - hostname: '', | | 890 | + hostname: '*', | 891 | 891 | hash: null, | 892 | 892 | search: null, | 893 | 893 | query: null, | 894 | | - pathname: '/*', | 895 | | - path: '/*', | 896 | | - href: 'https:///*' | | 894 | + pathname: '/', | | 895 | + path: '/', | | 896 | + href: 'https://*/' | 897 | 897 | }, | 898 | 898 |
| 899 | 899 | // The following two URLs are the same, but they differ for a capital A. | @@ -991,7 +991,22 @@ const parseTests = { | 991 | 991 | pathname: '/', | 992 | 992 | path: '/', | 993 | 993 | href: 'http://example.com/' | 994 | | - } | | 994 | + }, | | 995 | + | | 996 | + 'https://evil.com$.example.com': { | | 997 | + protocol: 'https:', | | 998 | + slashes: true, | | 999 | + auth: null, | | 1000 | + host: 'evil.com$.example.com', | | 1001 | + port: null, | | 1002 | + hostname: 'evil.com$.example.com', | | 1003 | + hash: null, | | 1004 | + search: null, | | 1005 | + query: null, | | 1006 | + pathname: '/', | | 1007 | + path: '/', | | 1008 | + href: 'https://evil.com$.example.com/' | | 1009 | + }, | 995 | 1010 | }; | 996 | 1011 |
| 997 | 1012 | for (const u in parseTests) { | |
|