-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy the behavior of browser `URL` interface and remove CR, HT, and LF from the input URL.
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ describe('url-parse', function () { | |
}); | ||
|
||
it('does not truncate the input string', function () { | ||
var input = 'foo\nbar\rbaz\u2028qux\u2029'; | ||
var input = 'foo\x0bbar\x0cbaz\u2028qux\u2029'; | ||
|
||
assume(parse.extractProtocol(input)).eql({ | ||
slashes: false, | ||
|
@@ -113,7 +113,16 @@ describe('url-parse', function () { | |
}); | ||
|
||
it('trimsLeft', function () { | ||
assume(parse.extractProtocol(' javascript://foo')).eql({ | ||
assume(parse.extractProtocol('\x0b\x0c javascript://foo')).eql({ | ||
slashes: true, | ||
protocol: 'javascript:', | ||
rest: 'foo', | ||
slashesCount: 2 | ||
}); | ||
}); | ||
|
||
it('removes CR, HT, and LF', function () { | ||
assume(parse.extractProtocol('jav\n\rasc\nript\r:/\t/fo\no')).eql({ | ||
slashes: true, | ||
protocol: 'javascript:', | ||
rest: 'foo', | ||
|
@@ -408,6 +417,31 @@ describe('url-parse', function () { | |
assume(parsed.href).equals('//example.com'); | ||
}); | ||
|
||
it('removes CR, HT, and LF', function () { | ||
var parsed = parse( | ||
'ht\ntp://a\rb:\tcd@exam\rple.com:80\t80/pat\thname?fo\no=b\rar#ba\tz' | ||
); | ||
|
||
assume(parsed.protocol).equals('http:'); | ||
assume(parsed.username).equals('ab'); | ||
assume(parsed.password).equals('cd'); | ||
assume(parsed.host).equals('example.com:8080'); | ||
assume(parsed.hostname).equals('example.com'); | ||
assume(parsed.port).equals('8080'); | ||
assume(parsed.pathname).equals('/pathname'); | ||
assume(parsed.query).equals('?foo=bar'); | ||
assume(parsed.hash).equals('#baz'); | ||
assume(parsed.href).equals( | ||
'http://ab:[email protected]:8080/pathname?foo=bar#baz' | ||
); | ||
|
||
parsed = parse('s\nip:al\rice@atl\tanta.com'); | ||
|
||
assume(parsed.protocol).equals('sip:'); | ||
assume(parsed.pathname).equals('[email protected]'); | ||
assume(parsed.href).equals('sip:[email protected]'); | ||
}); | ||
|
||
describe('origin', function () { | ||
it('generates an origin property', function () { | ||
var url = 'http://google.com:80/pathname' | ||
|