Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit319851b

Browse files
committed
[fix] Remove CR, HT, and LF
Copy the behavior of browser `URL` interface and remove CR, HT, and LFfrom the input URL.
1 parent4e53a8c commit319851b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

‎index.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
varrequired=require('requires-port')
44
,qs=require('querystringify')
5+
,CRHTLF=/[\n\r\t]/g
56
,slashes=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//
67
,protocolre=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i
78
,windowsDriveLetter=/^[a-zA-Z]:/
@@ -135,6 +136,7 @@ function isSpecial(scheme) {
135136
*/
136137
functionextractProtocol(address,location){
137138
address=trimLeft(address);
139+
address=address.replace(CRHTLF,'');
138140
location=location||{};
139141

140142
varmatch=protocolre.exec(address);
@@ -235,6 +237,7 @@ function resolve(relative, base) {
235237
*/
236238
functionUrl(address,location,parser){
237239
address=trimLeft(address);
240+
address=address.replace(CRHTLF,'');
238241

239242
if(!(thisinstanceofUrl)){
240243
returnnewUrl(address,location,parser);

‎test/test.js‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('url-parse', function () {
102102
});
103103

104104
it('does not truncate the input string',function(){
105-
varinput='foo\nbar\rbaz\u2028qux\u2029';
105+
varinput='foo\x0bbar\x0cbaz\u2028qux\u2029';
106106

107107
assume(parse.extractProtocol(input)).eql({
108108
slashes:false,
@@ -113,7 +113,16 @@ describe('url-parse', function () {
113113
});
114114

115115
it('trimsLeft',function(){
116-
assume(parse.extractProtocol(' #"diff-a561630bb56b82342bc66697aee2ad96efddcbc9d150665abd6fb7ecb7c0ab2f-116-116-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
116+
assume(parse.extractProtocol('\x0b\x0c #"diff-a561630bb56b82342bc66697aee2ad96efddcbc9d150665abd6fb7ecb7c0ab2f-116-117-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
117+
slashes:true,
118+
protocol:'#"diff-a561630bb56b82342bc66697aee2ad96efddcbc9d150665abd6fb7ecb7c0ab2f-116-119-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
119+
rest:'foo',
120+
slashesCount:2
121+
});
122+
});
123+
124+
it('removes CR, HT, and LF',function(){
125+
assume(parse.extractProtocol('jav\n\rasc\nript\r:/\t/fo\no')).eql({
117126
slashes:true,
118127
protocol:'#"diff-a561630bb56b82342bc66697aee2ad96efddcbc9d150665abd6fb7ecb7c0ab2f-119-128-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">119
128
rest:'foo',
@@ -408,6 +417,31 @@ describe('url-parse', function () {
408417
assume(parsed.href).equals('//example.com');
409418
});
410419

420+
it('removes CR, HT, and LF',function(){
421+
varparsed=parse(
422+
'ht\ntp://a\rb:\tcd@exam\rple.com:80\t80/pat\thname?fo\no=b\rar#ba\tz'
423+
);
424+
425+
assume(parsed.protocol).equals('http:');
426+
assume(parsed.username).equals('ab');
427+
assume(parsed.password).equals('cd');
428+
assume(parsed.host).equals('example.com:8080');
429+
assume(parsed.hostname).equals('example.com');
430+
assume(parsed.port).equals('8080');
431+
assume(parsed.pathname).equals('/pathname');
432+
assume(parsed.query).equals('?foo=bar');
433+
assume(parsed.hash).equals('#baz');
434+
assume(parsed.href).equals(
435+
'http://ab:cd@example.com:8080/pathname?foo=bar#baz'
436+
);
437+
438+
parsed=parse('s\nip:al\rice@atl\tanta.com');
439+
440+
assume(parsed.protocol).equals('sip:');
441+
assume(parsed.pathname).equals('alice@atlanta.com');
442+
assume(parsed.href).equals('sip:alice@atlanta.com');
443+
});
444+
411445
describe('origin',function(){
412446
it('generates an origin property',function(){
413447
varurl='http://google.com:80/pathname'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp