summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Rutledge Borden <evan.borden@skedge.me>2014-09-26 11:59:39 -0400
committerChris Dickinson <christopher.s.dickinson@gmail.com>2014-10-06 19:25:25 -0500
commit640ad632e3bf04fe07fa2b9dc3ca940c2e8d0261 (patch)
tree410eae6833913925950ebdda989983b2515bc606
parent8392e8cdfb71e8cc03e110f7b30ed104b3b136bd (diff)
downloadnode-640ad632e3bf04fe07fa2b9dc3ca940c2e8d0261.tar.gz
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>
-rw-r--r--lib/url.js12
-rw-r--r--test/simple/test-url.js24
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/url.js b/lib/url.js
index 646342420..d772b4f58 100644
--- a/lib/url.js
+++ b/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) {
diff --git a/test/simple/test-url.js b/test/simple/test-url.js
index e0a1b872d..8bfedcdf3 100644
--- a/test/simple/test-url.js
+++ b/test/simple/test-url.js
@@ -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:',