Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle backslashes like Node.js and Chrome #233

Merged
merged 1 commit into from Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/URI.js
Expand Up @@ -483,6 +483,12 @@
string = string.substring(0, pos);
}

// Copy chrome, IE, opera backslash-handling behavior.
// Back slashes before the query string get converted to forward slashes
// See: https://github.com/joyent/node/blob/master/lib/url.js
// See: https://code.google.com/p/chromium/issues/detail?id=25916
string = string.replace(/\\/g, '/');

// extract protocol
if (string.substring(0, 2) === '//') {
// relative-scheme
Expand Down
48 changes: 48 additions & 0 deletions test/urls.js
Expand Up @@ -1752,6 +1752,54 @@ var urls = [{
idn: false,
punycode: false
}
}, {
name: 'backslashes',
url: 'http://i.xss.com\\www.example.org/some/directory/file.html?query=string#fragment',
_url: 'http://i.xss.com/www.example.org/some/directory/file.html?query=string#fragment',
parts: {
protocol: 'http',
username: null,
password: null,
hostname: 'i.xss.com',
port: null,
path: '/www.example.org/some/directory/file.html',
query: 'query=string',
fragment: 'fragment'
},
accessors: {
protocol: 'http',
username: '',
password: '',
port: '',
path: '/www.example.org/some/directory/file.html',
query: 'query=string',
fragment: 'fragment',
resource: '/www.example.org/some/directory/file.html?query=string#fragment',
authority: 'i.xss.com',
userinfo: '',
subdomain: 'i',
domain: 'xss.com',
tld: 'com',
directory: '/www.example.org/some/directory',
filename: 'file.html',
suffix: 'html',
hash: '#fragment',
search: '?query=string',
host: 'i.xss.com',
hostname: 'i.xss.com'
},
is: {
urn: false,
url: true,
relative: false,
name: true,
sld: false,
ip: false,
ip4: false,
ip6: false,
idn: false,
punycode: false
}
}
];