url: treat \ the same as /
See https://code.google.com/p/chromium/issues/detail?id=25916 Parse URLs with backslashes the same as web browsers, by replacing all backslashes with forward slashes, except those that occur after the first # character.
This commit is contained in:
parent
1bd4f3a605
commit
9520adeb37
@ -107,6 +107,12 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy chrome, IE, opera backslash-handling behavior.
|
||||||
|
// See: https://code.google.com/p/chromium/issues/detail?id=25916
|
||||||
|
var hashSplit = url.split('#');
|
||||||
|
hashSplit[0] = hashSplit[0].replace(/\\/g, '/');
|
||||||
|
url = hashSplit.join('#');
|
||||||
|
|
||||||
var rest = url;
|
var rest = url;
|
||||||
|
|
||||||
// trim before proceeding.
|
// trim before proceeding.
|
||||||
|
@ -34,6 +34,28 @@ var parseTests = {
|
|||||||
'path': '//some_path'
|
'path': '//some_path'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'http:\\\\evil-phisher\\foo.html#h\\a\\s\\h': {
|
||||||
|
protocol: 'http:',
|
||||||
|
slashes: true,
|
||||||
|
host: 'evil-phisher',
|
||||||
|
hostname: 'evil-phisher',
|
||||||
|
pathname: '/foo.html',
|
||||||
|
path: '/foo.html',
|
||||||
|
hash: '#h\\a\\s\\h',
|
||||||
|
href: 'http://evil-phisher/foo.html#h\\a\\s\\h'
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
'http:\\\\evil-phisher\\foo.html': {
|
||||||
|
protocol: 'http:',
|
||||||
|
slashes: true,
|
||||||
|
host: 'evil-phisher',
|
||||||
|
hostname: 'evil-phisher',
|
||||||
|
pathname: '/foo.html',
|
||||||
|
path: '/foo.html',
|
||||||
|
href: 'http://evil-phisher/foo.html'
|
||||||
|
},
|
||||||
|
|
||||||
'HTTP://www.example.com/' : {
|
'HTTP://www.example.com/' : {
|
||||||
'href': 'http://www.example.com/',
|
'href': 'http://www.example.com/',
|
||||||
'protocol': 'http:',
|
'protocol': 'http:',
|
||||||
@ -1457,3 +1479,7 @@ relativeTests2.forEach(function(relativeTest) {
|
|||||||
'format(' + relativeTest[1] + ') == ' + expected +
|
'format(' + relativeTest[1] + ') == ' + expected +
|
||||||
'\nactual:' + actual);
|
'\nactual:' + actual);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// backslashes should be like forward slashes
|
||||||
|
var res = url.resolve('http://example.com/x', '\\\\foo.com\\bar');
|
||||||
|
assert.equal(res, 'http://foo.com/bar');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user