@@ -62,7 +62,7 @@ class DynamicPathSegment implements PathSegment {
6262 throw new BaseException (
6363 `Route generator for '${ this . name } ' was not included in parameters passed.` ) ;
6464 }
65- return normalizeString ( params . get ( this . name ) ) ;
65+ return encodeDynamicSegment ( normalizeString ( params . get ( this . name ) ) ) ;
6666 }
6767}
6868
@@ -130,7 +130,7 @@ export class ParamRoutePath implements RoutePath {
130130 captured . push ( currentUrlSegment . path ) ;
131131
132132 if ( pathSegment instanceof DynamicPathSegment ) {
133- positionalParams [ pathSegment . name ] = currentUrlSegment . path ;
133+ positionalParams [ pathSegment . name ] = decodeDynamicSegment ( currentUrlSegment . path ) ;
134134 } else if ( ! pathSegment . match ( currentUrlSegment . path ) ) {
135135 return null ;
136136 }
@@ -269,3 +269,43 @@ export class ParamRoutePath implements RoutePath {
269269 }
270270 static RESERVED_CHARS = RegExpWrapper . create ( '//|\\(|\\)|;|\\?|=' ) ;
271271}
272+
273+ let REGEXP_PERCENT = / % / g;
274+ let REGEXP_SLASH = / \/ / g;
275+ let REGEXP_OPEN_PARENT = / \( / g;
276+ let REGEXP_CLOSE_PARENT = / \) / g;
277+ let REGEXP_SEMICOLON = / ; / g;
278+
279+ function encodeDynamicSegment ( value : string ) : string {
280+ if ( isBlank ( value ) ) {
281+ return null ;
282+ }
283+
284+ value = StringWrapper . replaceAll ( value , REGEXP_PERCENT , '%25' ) ;
285+ value = StringWrapper . replaceAll ( value , REGEXP_SLASH , '%2F' ) ;
286+ value = StringWrapper . replaceAll ( value , REGEXP_OPEN_PARENT , '%28' ) ;
287+ value = StringWrapper . replaceAll ( value , REGEXP_CLOSE_PARENT , '%29' ) ;
288+ value = StringWrapper . replaceAll ( value , REGEXP_SEMICOLON , '%3B' ) ;
289+
290+ return value ;
291+ }
292+
293+ let REGEXP_ENC_SEMICOLON = / % 3 B / ig;
294+ let REGEXP_ENC_CLOSE_PARENT = / % 2 9 / ig;
295+ let REGEXP_ENC_OPEN_PARENT = / % 2 8 / ig;
296+ let REGEXP_ENC_SLASH = / % 2 F / ig;
297+ let REGEXP_ENC_PERCENT = / % 2 5 / ig;
298+
299+ function decodeDynamicSegment ( value : string ) : string {
300+ if ( isBlank ( value ) ) {
301+ return null ;
302+ }
303+
304+ value = StringWrapper . replaceAll ( value , REGEXP_ENC_SEMICOLON , ';' ) ;
305+ value = StringWrapper . replaceAll ( value , REGEXP_ENC_CLOSE_PARENT , ')' ) ;
306+ value = StringWrapper . replaceAll ( value , REGEXP_ENC_OPEN_PARENT , '(' ) ;
307+ value = StringWrapper . replaceAll ( value , REGEXP_ENC_SLASH , '/' ) ;
308+ value = StringWrapper . replaceAll ( value , REGEXP_ENC_PERCENT , '%' ) ;
309+
310+ return value ;
311+ }
0 commit comments