@@ -31,13 +31,14 @@ else {
3131}
3232/**
3333 * Encodes a path segment.
34- * RFC 3986 reserves !, ', (, ), and * as well, but we only escape space,
35- * like the implementations we are polyfilling.
34+ * RFC 3986 reserves !, ', (, ), and * and the implementation pipes the
35+ * output of encodeURIComponent to a hex encoding pass for these special
36+ * characters.
3637 */
3738function encodePathSegment ( segment ) {
38- return segment . replace ( / / g, function ( c ) {
39- return '%' + c . charCodeAt ( 0 ) . toString ( 16 )
40- } ) ;
39+ return encodeURIComponent ( segment ) . replace ( / [ ! ' ( ) * ] / g, function ( c ) {
40+ return '%' + c . charCodeAt ( 0 ) . toString ( 16 ) ;
41+ } ) ;
4142}
4243var URLSearchParams = /** @class */ ( function ( ) {
4344 function URLSearchParams ( init ) {
@@ -142,18 +143,11 @@ var URL = /** @class */ (function () {
142143 password : baseParts . password ,
143144 hostname : baseParts . hostname ,
144145 port : baseParts . port ,
146+ path : urlParts . path || baseParts . path ,
145147 query : urlParts . query || baseParts . query ,
146148 hash : urlParts . hash ,
147149 } ;
148150 }
149- if ( ! urlParts . path ) {
150- this . pathname = baseParts . path ;
151- } else if ( urlParts . path [ 0 ] !== '/' ) {
152- // relative path
153- this . pathname = baseParts . path + '/' + urlParts . path ;
154- } else {
155- this . pathname = urlParts . path
156- }
157151 // console.log(URL.parse(base), URL.parse(url), this._parts);
158152 }
159153 URL . init = function ( ) {
@@ -257,16 +251,12 @@ var URL = /** @class */ (function () {
257251 return this . _parts . path ? this . _parts . path : '/' ;
258252 } ,
259253 set : function ( value ) {
260- value = value . toString ( ) . split ( '/' ) ;
261- for ( var i = 0 ; i < value . length ; i ++ ) {
262- value [ i ] = encodePathSegment ( value [ i ] )
263- }
264- if ( value [ 0 ] ) {
265- // ensure joined string starts with slash.
266- value . unshift ( '' )
254+ var chunks = value . toString ( ) . split ( '/' ) . map ( encodePathSegment ) ;
255+ if ( chunks [ 0 ] ) {
256+ // ensure joined string starts with slash.
257+ chunks . unshift ( '' ) ;
267258 }
268- value = value . join ( '/' ) ;
269- this . _parts . path = value ;
259+ this . _parts . path = chunks . join ( '/' ) ;
270260 } ,
271261 enumerable : true ,
272262 configurable : true
0 commit comments