@@ -26,6 +26,29 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
2626 // .onChange() registry
2727 private _urlListeners : Function [ ] = [ ] ;
2828
29+ /**
30+ * Applys ng1-specific path parameter encoding
31+ *
32+ * The Angular 1 `$location` service is a bit weird.
33+ * It doesn't allow slashes to be encoded/decoded bi-directionally.
34+ *
35+ * See the writeup at https://github.com/angular-ui/ui-router/issues/2598
36+ *
37+ * This code patches the `path` parameter type so it encoded/decodes slashes as ~2F
38+ *
39+ * @param router
40+ */
41+ static monkeyPatchPathParameterType ( router : UIRouter ) {
42+ let pathType : ParamType = router . urlMatcherFactory . type ( 'path' ) ;
43+
44+ pathType . encode = ( val : any ) =>
45+ val != null ? val . toString ( ) . replace ( / ( ~ | \/ ) / g, m => ( { '~' : '~~' , '/' : '~2F' } [ m ] ) ) : val ;
46+
47+ pathType . decode = ( val : string ) =>
48+ val != null ? val . toString ( ) . replace ( / ( ~ ~ | ~ 2 F ) / g, m => ( { '~~' : '~' , '~2F' : '/' } [ m ] ) ) : val ;
49+
50+ }
51+
2952 dispose ( ) { }
3053
3154 constructor ( $locationProvider : ILocationProvider ) {
@@ -68,27 +91,4 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
6891 // Bind these LocationConfig functions to $browser
6992 createProxyFunctions ( _browser , this , _browser , [ 'baseHref' ] ) ;
7093 }
71-
72- /**
73- * Applys ng1-specific path parameter encoding
74- *
75- * The Angular 1 `$location` service is a bit weird.
76- * It doesn't allow slashes to be encoded/decoded bi-directionally.
77- *
78- * See the writeup at https://github.com/angular-ui/ui-router/issues/2598
79- *
80- * This code patches the `path` parameter type so it encoded/decodes slashes as ~2F
81- *
82- * @param router
83- */
84- static monkeyPatchPathParameterType ( router : UIRouter ) {
85- let pathType : ParamType = router . urlMatcherFactory . type ( 'path' ) ;
86-
87- pathType . encode = ( val : any ) =>
88- val != null ? val . toString ( ) . replace ( / ( ~ | \/ ) / g, m => ( { '~' : '~~' , '/' : '~2F' } [ m ] ) ) : val ;
89-
90- pathType . decode = ( val : string ) =>
91- val != null ? val . toString ( ) . replace ( / ( ~ ~ | ~ 2 F ) / g, m => ( { '~~' : '~' , '~2F' : '/' } [ m ] ) ) : val ;
92-
93- }
9494}
0 commit comments