From 8a0bd4e0b596b21bf8b351344fcdd2a9a26686ec Mon Sep 17 00:00:00 2001 From: Petka Antonov Date: Thu, 8 Jan 2015 18:12:33 +0200 Subject: [PATCH] Port fix to https://github.com/joyent/node/issues/8458 --- src/urlparser.js | 12 ++++++------ test/node.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/urlparser.js b/src/urlparser.js index 3f3631f..31e812d 100644 --- a/src/urlparser.js +++ b/src/urlparser.js @@ -679,12 +679,12 @@ Url.prototype._clone = function Url$_clone() { }; Url.prototype._getComponentEscaped = -function Url$_getComponentEscaped(str, start, end, isAfterHash) { +function Url$_getComponentEscaped(str, start, end, isAfterQuery) { var cur = start; var i = start; var ret = ""; - var autoEscapeMap = isAfterHash - ? this._afterHashAutoEscapeMap : this._autoEscapeMap; + var autoEscapeMap = isAfterQuery + ? this._afterQueryAutoEscapeMap : this._autoEscapeMap; for (; i <= end; ++i) { var ch = str.charCodeAt(i); var escaped = autoEscapeMap[ch]; @@ -764,7 +764,7 @@ Url.prototype._parseQuery = function Url$_parseQuery(str, start, end) { var query; if (escape) { - query = this._getComponentEscaped(str, queryStart, queryEnd, false); + query = this._getComponentEscaped(str, queryStart, queryEnd, true); } else { query = str.slice(queryStart, queryEnd + 1); @@ -982,7 +982,7 @@ for (var i = 0, len = autoEscape.length; i < len; ++i) { } autoEscapeMap[c.charCodeAt(0)] = esc; } -var afterHashAutoEscapeMap = autoEscapeMap.slice(); +var afterQueryAutoEscapeMap = autoEscapeMap.slice(); autoEscapeMap[0x5C /*'\'*/] = "/"; var slashProtocols = Url.prototype._slashProtocols = { @@ -1031,7 +1031,7 @@ Url.prototype._noPrependSlashHostEnders = makeAsciiTable( ); Url.prototype._autoEscapeMap = autoEscapeMap; -Url.prototype._afterHashAutoEscapeMap = afterHashAutoEscapeMap; +Url.prototype._afterQueryAutoEscapeMap = afterQueryAutoEscapeMap; module.exports = Url; diff --git a/test/node.js b/test/node.js index 4776de0..a6a8e76 100644 --- a/test/node.js +++ b/test/node.js @@ -36,6 +36,29 @@ 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:',