url: fixed encoding for slash switching emulation.
Fixes: https://github.com/joyent/node/issues/8458 Reviewed-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
This commit is contained in:
parent
8392e8cdfb
commit
640ad632e3
12
lib/url.js
12
lib/url.js
@ -111,10 +111,14 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
||||
}
|
||||
|
||||
// Copy chrome, IE, opera backslash-handling behavior.
|
||||
// Back slashes before the query string get converted to forward slashes
|
||||
// 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 queryIndex = url.indexOf('?'),
|
||||
splitter = (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
|
||||
uSplit = url.split(splitter),
|
||||
slashRegex = /\\/g;
|
||||
uSplit[0] = uSplit[0].replace(slashRegex, '/');
|
||||
url = uSplit.join(splitter);
|
||||
|
||||
var rest = url;
|
||||
|
||||
@ -122,7 +126,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
||||
// This is to support parse stuff like " http://foo.com \n"
|
||||
rest = rest.trim();
|
||||
|
||||
if (!slashesDenoteHost && hashSplit.length === 1) {
|
||||
if (!slashesDenoteHost && url.split('#').length === 1) {
|
||||
// Try fast path regexp
|
||||
var simplePath = simplePathPattern.exec(rest);
|
||||
if (simplePath) {
|
||||
|
@ -45,6 +45,30 @@ var parseTests = {
|
||||
href: 'http://evil-phisher/foo.html#h%5Ca%5Cs%5Ch'
|
||||
},
|
||||
|
||||
'http:\\\\evil-phisher\\foo.html?json="\\"foo\\""#h\\a\\s\\h': {
|
||||
protocol: 'http:',
|
||||
slashes: true,
|
||||
host: 'evil-phisher',
|
||||
hostname: 'evil-phisher',
|
||||
pathname: '/foo.html',
|
||||
search: '?json=%22%5C%22foo%5C%22%22',
|
||||
query: 'json=%22%5C%22foo%5C%22%22',
|
||||
path: '/foo.html?json=%22%5C%22foo%5C%22%22',
|
||||
hash: '#h%5Ca%5Cs%5Ch',
|
||||
href: 'http://evil-phisher/foo.html?json=%22%5C%22foo%5C%22%22#h%5Ca%5Cs%5Ch'
|
||||
},
|
||||
|
||||
'http:\\\\evil-phisher\\foo.html#h\\a\\s\\h?blarg': {
|
||||
protocol: 'http:',
|
||||
slashes: true,
|
||||
host: 'evil-phisher',
|
||||
hostname: 'evil-phisher',
|
||||
pathname: '/foo.html',
|
||||
path: '/foo.html',
|
||||
hash: '#h%5Ca%5Cs%5Ch?blarg',
|
||||
href: 'http://evil-phisher/foo.html#h%5Ca%5Cs%5Ch?blarg'
|
||||
},
|
||||
|
||||
|
||||
'http:\\\\evil-phisher\\foo.html': {
|
||||
protocol: 'http:',
|
||||
|
Loading…
x
Reference in New Issue
Block a user