mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Close #954 URL parsing/formatting corrections
1. Allow single-quotes in urls, but escape them. 2. Add comments about which RFCs we're following for guidance. 3. Handle any invalid character in the hostname portion. 4. lcase protocol and hostname portions, since they are case-insensitive.
This commit is contained in:
1 parent
d3d35ec3ca
commit
90802d628d
2 files changed
+171
-19
No files matched your search
+106
-12
@@ -32,6 +32,99 @@ var parseTests = {
|
||||
'href': '//some_path',
|
||||
'pathname': '//some_path'
|
||||
},
|
||||
'HTTP://www.example.com/' : {
|
||||
'href': 'http://www.example.com/',
|
||||
'protocol': 'http:',
|
||||
'host': 'www.example.com',
|
||||
'hostname': 'www.example.com',
|
||||
'pathname': '/'
|
||||
},
|
||||
'http://www.ExAmPlE.com/' : {
|
||||
'href': 'http://www.example.com/',
|
||||
'protocol': 'http:',
|
||||
'host': 'www.example.com',
|
||||
'hostname': 'www.example.com',
|
||||
'pathname': '/'
|
||||
|
||||
},
|
||||
'http://user:pw@www.ExAmPlE.com/' : {
|
||||
'href': 'http://user:pw@www.example.com/',
|
||||
'protocol': 'http:',
|
||||
'auth': 'user:pw',
|
||||
'host': 'user:pw@www.example.com',
|
||||
'hostname': 'www.example.com',
|
||||
'pathname': '/'
|
||||
|
||||
},
|
||||
'http://USER:PW@www.ExAmPlE.com/' : {
|
||||
'href': 'http://USER:PW@www.example.com/',
|
||||
'protocol': 'http:',
|
||||
'auth': 'USER:PW',
|
||||
'host': 'USER:PW@www.example.com',
|
||||
'hostname': 'www.example.com',
|
||||
'pathname': '/'
|
||||
},
|
||||
'http://x.com/path?that\'s#all, folks' : {
|
||||
'href': 'http://x.com/path?that%27s#all,',
|
||||
'protocol': 'http:',
|
||||
'host': 'x.com',
|
||||
'hostname': 'x.com',
|
||||
'search': '?that%27s',
|
||||
'query': 'that%27s',
|
||||
'pathname': '/path',
|
||||
'hash': '#all,'
|
||||
},
|
||||
'HTTP://X.COM/Y' : {
|
||||
'href': 'http://x.com/Y',
|
||||
'protocol': 'http:',
|
||||
'host': 'x.com',
|
||||
'hostname': 'x.com',
|
||||
'pathname': '/Y',
|
||||
},
|
||||
// an unexpected invalid char in the hostname.
|
||||
'HtTp://x.y.cOm*a/b/c?d=e#f g<h>i' : {
|
||||
'href': 'http://x.y.com/*a/b/c?d=e#f',
|
||||
'protocol': 'http:',
|
||||
'host': 'x.y.com',
|
||||
'hostname': 'x.y.com',
|
||||
'pathname': '/*a/b/c',
|
||||
'search': '?d=e',
|
||||
'query': 'd=e',
|
||||
'hash': '#f'
|
||||
},
|
||||
// make sure that we don't accidentally lcast the path parts.
|
||||
'HtTp://x.y.cOm*A/b/c?d=e#f g<h>i' : {
|
||||
'href': 'http://x.y.com/*A/b/c?d=e#f',
|
||||
'protocol': 'http:',
|
||||
'host': 'x.y.com',
|
||||
'hostname': 'x.y.com',
|
||||
'pathname': '/*A/b/c',
|
||||
'search': '?d=e',
|
||||
'query': 'd=e',
|
||||
'hash': '#f'
|
||||
},
|
||||
'http://x...y...#p': {
|
||||
'href': 'http://x...y.../#p',
|
||||
'protocol': 'http:',
|
||||
'host': 'x...y...',
|
||||
'hostname': 'x...y...',
|
||||
'hash': '#p',
|
||||
'pathname': '/'
|
||||
},
|
||||
'http://x/p/"quoted"': {
|
||||
'href': 'http://x/p/',
|
||||
'protocol':'http:',
|
||||
'host': 'x',
|
||||
'hostname': 'x',
|
||||
'pathname': '/p/'
|
||||
},
|
||||
'<http://goo.corn/bread> Is a URL!': {
|
||||
'href': 'http://goo.corn/bread',
|
||||
'protocol': 'http:',
|
||||
'host': 'goo.corn',
|
||||
'hostname': 'goo.corn',
|
||||
'pathname': '/bread'
|
||||
},
|
||||
'http://www.narwhaljs.org/blog/categories?id=news' : {
|
||||
'href': 'http://www.narwhaljs.org/blog/categories?id=news',
|
||||
'protocol': 'http:',
|
||||
@@ -58,17 +151,18 @@ var parseTests = {
|
||||
'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'pathname': '/vt/lyrs=m@114'
|
||||
},
|
||||
'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : {
|
||||
'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' +
|
||||
'&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'protocol': 'http:',
|
||||
'host': 'user:pass@mt0.google.com',
|
||||
'auth': 'user:pass',
|
||||
'hostname': 'mt0.google.com',
|
||||
'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'pathname': '/vt/lyrs=m@114'
|
||||
},
|
||||
'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=':
|
||||
{
|
||||
'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' +
|
||||
'&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'protocol': 'http:',
|
||||
'host': 'user:pass@mt0.google.com',
|
||||
'auth': 'user:pass',
|
||||
'hostname': 'mt0.google.com',
|
||||
'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
|
||||
'pathname': '/vt/lyrs=m@114'
|
||||
},
|
||||
'file:///etc/passwd' : {
|
||||
'href': 'file:///etc/passwd',
|
||||
'protocol': 'file:',
|
||||
@@ -154,7 +248,7 @@ for (var u in parseTests) {
|
||||
'parse(' + u + ').' + i + ' == ' + e + '\nactual: ' + a);
|
||||
}
|
||||
|
||||
var expected = u,
|
||||
var expected = parseTests[u].href,
|
||||
actual = url.format(parseTests[u]);
|
||||
|
||||
assert.equal(expected, actual,
|
||||
|
||||
Reference in new issue
Block a user