-
Notifications
You must be signed in to change notification settings - Fork 107
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
[security] More backslash fixes #197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,9 +190,10 @@ describe('url-parse', function () { | |
, parsed = parse(url); | ||
|
||
assume(parsed.port).equals(''); | ||
assume(parsed.pathname).equals('/'); | ||
assume(parsed.host).equals('example.com'); | ||
assume(parsed.hostname).equals('example.com'); | ||
assume(parsed.href).equals('http://example.com'); | ||
assume(parsed.href).equals('http://example.com/'); | ||
}); | ||
|
||
it('understands an / as pathname', function () { | ||
|
@@ -242,16 +243,30 @@ describe('url-parse', function () { | |
assume(parsed.hostname).equals('google.com'); | ||
assume(parsed.hash).equals('#what\\is going on'); | ||
|
||
parsed = parse('//\\what-is-up.com'); | ||
parsed = parse('http://yolo.com\\what-is-up.com'); | ||
assume(parsed.pathname).equals('/what-is-up.com'); | ||
}); | ||
|
||
it('correctly ignores multiple slashes //', function () { | ||
var url = '////what-is-up.com' | ||
, parsed = parse(url); | ||
|
||
assume(parsed.host).equals(''); | ||
assume(parsed.hostname).equals(''); | ||
assume(parsed.host).equals('what-is-up.com'); | ||
assume(parsed.href).equals('//what-is-up.com/'); | ||
}); | ||
|
||
it('does not see a slash after the protocol as path', function () { | ||
var url = 'https:\\/github.com/foo/bar' | ||
, parsed = parse(url); | ||
|
||
assume(parsed.host).equals('github.com'); | ||
assume(parsed.hostname).equals('github.com'); | ||
assume(parsed.pathname).equals('/foo/bar'); | ||
|
||
url = 'https:/\/\/\github.com/foo/bar'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @3rd-Eden did you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just testing that literally any slash (forward/backward) or combination of both is allowed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, then it should be |
||
assume(parsed.host).equals('github.com'); | ||
assume(parsed.hostname).equals('github.com'); | ||
assume(parsed.pathname).equals('/foo/bar'); | ||
}); | ||
|
||
describe('origin', function () { | ||
|
@@ -327,32 +342,52 @@ describe('url-parse', function () { | |
it('extracts the right protocol from a url', function () { | ||
var testData = [ | ||
{ | ||
href: 'http://example.com', | ||
href: 'http://example.com/', | ||
protocol: 'http:', | ||
pathname: '' | ||
pathname: '/', | ||
slashes: true | ||
}, | ||
{ | ||
href: 'ws://example.com/', | ||
protocol: 'ws:', | ||
pathname: '/', | ||
slashes: true | ||
}, | ||
{ | ||
href: 'wss://example.com/', | ||
protocol: 'wss:', | ||
pathname: '/', | ||
slashes: true | ||
}, | ||
{ | ||
href: 'mailto:test@example.com', | ||
pathname: 'test@example.com', | ||
protocol: 'mailto:' | ||
protocol: 'mailto:', | ||
slashes: false | ||
}, | ||
{ | ||
href: 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', | ||
pathname: 'text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', | ||
protocol: 'data:' | ||
protocol: 'data:', | ||
slashes: false, | ||
}, | ||
{ | ||
href: 'sip:alice@atlanta.com', | ||
pathname: 'alice@atlanta.com', | ||
protocol: 'sip:' | ||
protocol: 'sip:', | ||
slashes: false, | ||
} | ||
]; | ||
|
||
var data; | ||
var data, test; | ||
for (var i = 0, len = testData.length; i < len; ++i) { | ||
data = parse(testData[i].href); | ||
assume(data.protocol).equals(testData[i].protocol); | ||
assume(data.pathname).equals(testData[i].pathname); | ||
test = testData[i]; | ||
data = parse(test.href); | ||
|
||
assume(data.protocol).equals(test.protocol); | ||
assume(data.pathname).equals(test.pathname); | ||
assume(data.slashes).equals(test.slashes); | ||
assume(data.href).equals(test.href); | ||
} | ||
}); | ||
|
||
|
@@ -391,13 +426,14 @@ describe('url-parse', function () { | |
}); | ||
|
||
it('parses ipv6 with auth', function () { | ||
var url = 'http://user:password@[3ffe:2a00:100:7031::1]:8080' | ||
var url = 'http://user:password@[3ffe:2a00:100:7031::1]:8080/' | ||
, parsed = parse(url); | ||
|
||
assume(parsed.username).equals('user'); | ||
assume(parsed.password).equals('password'); | ||
assume(parsed.host).equals('[3ffe:2a00:100:7031::1]:8080'); | ||
assume(parsed.hostname).equals('[3ffe:2a00:100:7031::1]'); | ||
assume(parsed.pathname).equals('/'); | ||
assume(parsed.href).equals(url); | ||
}); | ||
|
||
|
@@ -467,7 +503,7 @@ describe('url-parse', function () { | |
|
||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
assume(data.href).equals('http://localhost/'); | ||
}); | ||
|
||
it('inherits port numbers for relative urls', function () { | ||
|
@@ -516,7 +552,8 @@ describe('url-parse', function () { | |
}); | ||
|
||
it('inherits protocol for relative protocols', function () { | ||
var data = parse('//foo.com/foo', parse('http://sub.example.com:808/')); | ||
var lolcation = parse('http://sub.example.com:808/') | ||
, data = parse('//foo.com/foo', lolcation); | ||
|
||
assume(data.port).equals(''); | ||
assume(data.host).equals('foo.com'); | ||
|
@@ -529,13 +566,13 @@ describe('url-parse', function () { | |
|
||
assume(data.port).equals(''); | ||
assume(data.host).equals('localhost'); | ||
assume(data.href).equals('http://localhost'); | ||
assume(data.href).equals('http://localhost/'); | ||
}); | ||
|
||
it('resolves pathname for relative urls', function () { | ||
var data, i = 0; | ||
var tests = [ | ||
['', 'http://foo.com', ''], | ||
['', 'http://foo.com', '/'], | ||
['', 'http://foo.com/', '/'], | ||
['', 'http://foo.com/a', '/a'], | ||
['a', 'http://foo.com', '/a'], | ||
|
@@ -722,12 +759,12 @@ describe('url-parse', function () { | |
data.set('hash', 'usage'); | ||
|
||
assume(data.hash).equals('#usage'); | ||
assume(data.href).equals('http://example.com#usage'); | ||
assume(data.href).equals('http://example.com/#usage'); | ||
|
||
data.set('hash', '#license'); | ||
|
||
assume(data.hash).equals('#license'); | ||
assume(data.href).equals('http://example.com#license'); | ||
assume(data.href).equals('http://example.com/#license'); | ||
}); | ||
|
||
it('updates the port when updating host', function () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cause break change, see below demo code:
This PR cause pathname change from 'cone/operate' to '/cone/cone/operate'
debugger snapshot:
input:
output:
i don't know of pass '/cone/operate' is a valid argument, if no, i think throw error is a better way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create an issue about this so we can track it? We do known issue with relative paths atm see #200 so it might be related to this bug.