Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Jan 8, 2015
1 parent 3647e55 commit 8a0bd4e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/urlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ Url.prototype._noPrependSlashHostEnders = makeAsciiTable(
);

Url.prototype._autoEscapeMap = autoEscapeMap;
Url.prototype._afterHashAutoEscapeMap = afterHashAutoEscapeMap;
Url.prototype._afterQueryAutoEscapeMap = afterQueryAutoEscapeMap;

module.exports = Url;

Expand Down
23 changes: 23 additions & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:',
Expand Down

0 comments on commit 8a0bd4e

Please sign in to comment.