File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ impl Fastly {
17
17
}
18
18
19
19
pub fn purge ( & mut self , path : & str ) -> Result < ( ) , Error > {
20
- let sanitized_path = path . trim_start_matches ( '/' ) ;
20
+ let surrogate_key = path_to_surrogate_key ( path ) ;
21
21
let url = format ! (
22
22
"https://api.fastly.com/service/{}/purge/{}" ,
23
- self . service_id, sanitized_path
23
+ self . service_id, surrogate_key
24
24
) ;
25
25
26
26
self . start_new_request ( ) ?;
@@ -43,3 +43,21 @@ impl Fastly {
43
43
Ok ( ( ) )
44
44
}
45
45
}
46
+
47
+ fn path_to_surrogate_key ( path : & str ) -> String {
48
+ path. chars ( ) . filter ( |c| c. is_alphanumeric ( ) ) . collect ( )
49
+ }
50
+
51
+ #[ cfg( test) ]
52
+ mod tests {
53
+ use super :: * ;
54
+
55
+ #[ test]
56
+ fn path_to_surrogate_key_dist ( ) {
57
+ let path = "/dist/*" ;
58
+
59
+ let surrogate_key = path_to_surrogate_key ( path) ;
60
+
61
+ assert_eq ! ( "dist" , surrogate_key) ;
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments