From 53af67e6fac39f855b2112065d64d436edb0c745 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Mon, 4 May 2020 17:15:00 +0000 Subject: [PATCH] Fix path with ~ --- samples/test1 | 2 ++ src/state.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/test1 b/samples/test1 index 8cebc79..43f3b0f 100644 --- a/samples/test1 +++ b/samples/test1 @@ -22,6 +22,8 @@ path: /var/log/nginx.log path: ./folder/.neomake@04fd.log +home: ~/.gnu/.config.txt + 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 10.3.23.42 lorem 123.2.3.4 lorem 230.23.33.34 diff --git a/src/state.rs b/src/state.rs index 2c57e10..fc7ae62 100644 --- a/src/state.rs +++ b/src/state.rs @@ -9,7 +9,7 @@ const PATTERNS: [(&'static str, &'static str); 13] = [ ("url", r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ ]+)"), ("diff_a", r"--- a/([^ ]+)"), ("diff_b", r"\+\+\+ b/([^ ]+)"), - ("path", r"(([.\w\-@]+)?(/[.\w\-@]+)+)"), + ("path", r"(([.\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}"), @@ -224,6 +224,16 @@ mod tests { assert_eq!(results.get(2).unwrap().text.clone(), "../log/kern.log"); } + #[test] + fn match_home() { + let lines = split("Lorem ~/.gnu/.config.txt, lorem"); + let custom = [].to_vec(); + let results = State::new(&lines, "abcd", &custom).matches(false, false); + + assert_eq!(results.len(), 1); + assert_eq!(results.get(0).unwrap().text.clone(), "~/.gnu/.config.txt"); + } + #[test] fn match_uids() { let lines = split("Lorem ipsum 123e4567-e89b-12d3-a456-426655440000 lorem\n Lorem lorem lorem");