@@ -26,6 +26,29 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
26
26
// .onChange() registry
27
27
private _urlListeners : Function [ ] = [ ] ;
28
28
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
+
29
52
dispose ( ) { }
30
53
31
54
constructor ( $locationProvider : ILocationProvider ) {
@@ -68,27 +91,4 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
68
91
// Bind these LocationConfig functions to $browser
69
92
createProxyFunctions ( _browser , this , _browser , [ 'baseHref' ] ) ;
70
93
}
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
- }
94
94
}
0 commit comments