@@ -32,12 +32,16 @@ exports.format = urlFormat;
3232// compiled once on the first module load.
3333var protocolPattern = / ^ ( [ a - z 0 - 9 . + - ] + : ) / i,
3434 portPattern = / : [ 0 - 9 ] * $ / ,
35+
3536 // RFC 2396: characters reserved for delimiting URLs.
37+ // We actually just auto-escape these.
3638 delims = [ '<' , '>' , '"' , '`' , ' ' , '\r' , '\n' , '\t' ] ,
39+
3740 // RFC 2396: characters not allowed for various reasons.
3841 unwise = [ '{' , '}' , '|' , '\\' , '^' , '~' , '`' ] . concat ( delims ) ,
42+
3943 // Allowed by RFCs, but cause of XSS attacks. Always escape these.
40- autoEscape = [ '\'' ] ,
44+ autoEscape = [ '\'' ] . concat ( delims ) ,
4145 // Characters that are never ever allowed in a hostname.
4246 // Note that any invalid chars are also handled, but these
4347 // are the ones that are *expected* to be seen, so we fast-path
@@ -95,13 +99,9 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
9599 var out = { } ,
96100 rest = url ;
97101
98- // cut off any delimiters.
99- // This is to support parse stuff like "<http://foo.com>"
100- for ( var i = 0 , l = rest . length ; i < l ; i ++ ) {
101- if ( delims . indexOf ( rest . charAt ( i ) ) === - 1 ) break ;
102- }
103- if ( i !== 0 ) rest = rest . substr ( i ) ;
104-
102+ // trim before proceeding.
103+ // This is to support parse stuff like " http://foo.com \n"
104+ rest = rest . trim ( ) ;
105105
106106 var proto = protocolPattern . exec ( rest ) ;
107107 if ( proto ) {
@@ -271,16 +271,6 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
271271 }
272272 rest = rest . split ( ae ) . join ( esc ) ;
273273 }
274-
275- // Now make sure that delims never appear in a url.
276- var chop = rest . length ;
277- for ( var i = 0 , l = delims . length ; i < l ; i ++ ) {
278- var c = rest . indexOf ( delims [ i ] ) ;
279- if ( c !== - 1 ) {
280- chop = Math . min ( c , chop ) ;
281- }
282- }
283- rest = rest . substr ( 0 , chop ) ;
284274 }
285275
286276
0 commit comments