From 2dc167218f6ecea545d77840ee56a1578d89e412 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Tue, 17 Jan 2023 20:18:06 +0000 Subject: [PATCH] Support paths with $ symbols It is quite common in some web frameworks (NextJS, Remix) to define routes with `$` on them. Adding support for paths that represent those routes. --- src/state.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/state.rs b/src/state.rs index 7318091..2e3e00c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -14,7 +14,7 @@ const PATTERNS: [(&'static str, &'static str); 15] = [ ("diff_a", r"--- a/([^ ]+)"), ("diff_b", r"\+\+\+ b/([^ ]+)"), ("docker", r"sha256:([0-9a-f]{64})"), - ("path", r"(?P([.\w\-@~\[\]]+)?(/[.\w\-@\[\]]+)+)"), + ("path", r"(?P([.\w\-@$~\[\]]+)?(/[.\w\-@$\[\]]+)+)"), ("color", r"#[0-9a-fA-F]{6}"), ("uid", r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"), ("ipfs", r"Qm[0-9a-zA-Z]{44}"), @@ -255,6 +255,17 @@ mod tests { assert_eq!(results.get(2).unwrap().text.clone(), "../log/kern.log"); } + #[test] + fn match_routes() { + let lines = split("Lorem /app/routes/$routeId/$objectId, lorem\n Lorem /app/routes/$sectionId"); + let custom = [].to_vec(); + let results = State::new(&lines, "abcd", &custom).matches(false, false); + + assert_eq!(results.len(), 2); + assert_eq!(results.get(0).unwrap().text.clone(), "/app/routes/$routeId/$objectId"); + assert_eq!(results.get(1).unwrap().text.clone(), "/app/routes/$sectionId"); + } + #[test] fn match_home() { let lines = split("Lorem ~/.gnu/.config.txt, lorem");