File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -118,12 +118,13 @@ function extractProtocol(address) {
118
118
119
119
var match = protocolre . exec ( address )
120
120
, protocol = match [ 1 ] ? match [ 1 ] . toLowerCase ( ) : ''
121
- , slashes = ! ! ( match [ 2 ] && match [ 2 ] . length >= 2 ) ;
121
+ , slashes = ! ! ( match [ 2 ] && match [ 2 ] . length >= 2 )
122
+ , rest = match [ 2 ] && match [ 2 ] . length === 1 ? '/' + match [ 3 ] : match [ 3 ] ;
122
123
123
124
return {
124
125
protocol : protocol ,
125
126
slashes : slashes ,
126
- rest : match [ 3 ]
127
+ rest : rest
127
128
} ;
128
129
}
129
130
Original file line number Diff line number Diff line change @@ -83,6 +83,20 @@ describe('url-parse', function () {
83
83
} ) ;
84
84
} ) ;
85
85
86
+ it ( 'correctly resolves paths' , function ( ) {
87
+ assume ( parse . extractProtocol ( '/foo' ) ) . eql ( {
88
+ slashes : false ,
89
+ protocol : '' ,
90
+ rest : '/foo'
91
+ } ) ;
92
+
93
+ assume ( parse . extractProtocol ( '//foo/bar' ) ) . eql ( {
94
+ slashes : true ,
95
+ protocol : '' ,
96
+ rest : 'foo/bar'
97
+ } ) ;
98
+ } ) ;
99
+
86
100
it ( 'does not truncate the input string' , function ( ) {
87
101
var input = 'foo\nbar\rbaz\u2028qux\u2029' ;
88
102
@@ -209,6 +223,20 @@ describe('url-parse', function () {
209
223
assume ( parsed . href ) . equals ( 'http://example.com/' ) ;
210
224
} ) ;
211
225
226
+ it ( 'correctly parses pathnames for relative paths' , function ( ) {
227
+ var url = '/dataApi/PROD/ws'
228
+ , parsed = parse ( url , 'http://localhost:3000/PROD/trends' ) ;
229
+
230
+ assume ( parsed . pathname ) . equals ( '/dataApi/PROD/ws' ) ;
231
+
232
+ url = '/sections/?project=default'
233
+ parsed = parse ( url , 'http://example.com/foo/bar' ) ;
234
+
235
+ assume ( parsed . pathname ) . equals ( '/sections/' ) ;
236
+ assume ( parsed . hostname ) . equals ( 'example.com' ) ;
237
+ assume ( parsed . href ) . equals ( 'http://example.com/sections/?project=default' ) ;
238
+ } ) ;
239
+
212
240
it ( 'does not care about spaces' , function ( ) {
213
241
var url = 'http://x.com/path?that\'s#all, folks'
214
242
, parsed = parse ( url ) ;
You can’t perform that action at this time.
0 commit comments