summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/url.js12
1 files changed, 8 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) {