GeezerVison is showing github.com — url: remove \t \n \r in url.parse() similar to WHATWG · nodejs/node@5d964cd
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 +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -319,6 +319,10 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | 319 | 319 | case CHAR_TAB: | 320 | 320 | case CHAR_LINE_FEED: | 321 | 321 | case CHAR_CARRIAGE_RETURN: | | 322 | + // WHATWG URL removes tabs, newlines, and carriage returns. Let's do that too. | | 323 | + rest = rest.slice(0, i) + rest.slice(i + 1); | | 324 | + i -= 1; | | 325 | + break; | 322 | 326 | case CHAR_SPACE: | 323 | 327 | case CHAR_DOUBLE_QUOTE: | 324 | 328 | case CHAR_PERCENT: | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-url-parse-format.js +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -853,16 +853,16 @@ const parseTests = { | 853 | 853 | 'http://a\r" \t\n<\'b:b@c\r\nd/e?f': { | 854 | 854 | protocol: 'http:', | 855 | 855 | slashes: true, | 856 | | - auth: 'a\r" \t\n<\'b:b', | 857 | | - host: 'c', | | 856 | + auth: 'a" <\'b:b', | | 857 | + host: 'cd', | 858 | 858 | port: null, | 859 | | - hostname: 'c', | | 859 | + hostname: 'cd', | 860 | 860 | hash: null, | 861 | 861 | search: '?f', | 862 | 862 | query: 'f', | 863 | | - pathname: '%0D%0Ad/e', | 864 | | - path: '%0D%0Ad/e?f', | 865 | | - href: 'http://a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f' | | 863 | + pathname: '/e', | | 864 | + path: '/e?f', | | 865 | + href: 'http://a%22%20%3C\'b:b@cd/e?f' | 866 | 866 | }, | 867 | 867 |
| 868 | 868 | // Git urls used by npm | @@ -1023,7 +1023,7 @@ for (const u in parseTests) { | 1023 | 1023 | assert.deepStrictEqual( | 1024 | 1024 | actual, | 1025 | 1025 | expected, | 1026 | | - `expected ${inspect(expected)}, got ${inspect(actual)}` | | 1026 | + `parsing ${u} and expected ${inspect(expected)} but got ${inspect(actual)}` | 1027 | 1027 | ); | 1028 | 1028 | assert.deepStrictEqual( | 1029 | 1029 | spaced, | |
|