Skip to content

Commit 348f025

Browse files
authored
Merge pull request #73 from jdno/simplify-surrogate-key
Simplify the surrogate key for Fastly
2 parents ec39aa7 + bfa4116 commit 348f025

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/fastly.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ impl Fastly {
1717
}
1818

1919
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);
2121
let url = format!(
2222
"https://api.fastly.com/service/{}/purge/{}",
23-
self.service_id, sanitized_path
23+
self.service_id, surrogate_key
2424
);
2525

2626
self.start_new_request()?;
@@ -43,3 +43,21 @@ impl Fastly {
4343
Ok(())
4444
}
4545
}
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+
}

0 commit comments

Comments
 (0)