From 22908e0dfef18e8accf9a2125f8349b448aea2e6 Mon Sep 17 00:00:00 2001 From: Canop Date: Wed, 29 Dec 2021 09:16:38 +0100 Subject: fix wrong translation from exact pattern to regex pattern Fix: regex pattern automatically built from content pattern when going from a tree search to a file preview isn't escaped Fix #472 --- CHANGELOG.md | 4 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/pattern/content_pattern.rs | 2 +- src/pattern/input_pattern.rs | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e752df4..1098fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### v1.8.1 - 2021-12-29 + +- fix regex pattern automatically built from content pattern when going from a tree search to a file preview isn't escaped - Fix #472 + ### v1.8.0 - 2021-12-26 - alt-i bound to toggle_git_ignore diff --git a/Cargo.lock b/Cargo.lock index e8a695b..9bd32e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,7 +140,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "broot" -version = "1.8.0" +version = "1.8.1" dependencies = [ "ahash 0.7.6", "ansi_colours", diff --git a/Cargo.toml b/Cargo.toml index 8fd22a2..d8fef0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "broot" -version = "1.8.0" +version = "1.8.1" authors = ["dystroy "] repository = "https://github.com/Canop/broot" documentation = "https://dystroy.org/broot" diff --git a/src/pattern/content_pattern.rs b/src/pattern/content_pattern.rs index 3521eec..434e741 100644 --- a/src/pattern/content_pattern.rs +++ b/src/pattern/content_pattern.rs @@ -39,7 +39,7 @@ impl ContentExactPattern { } pub fn to_regex_parts(&self) -> (String, String) { - (self.as_str().to_string(), "".to_string()) + (regex::escape(self.as_str()), "".to_string()) } pub fn score_of(&self, candidate: Candidate) -> Option { diff --git a/src/pattern/input_pattern.rs b/src/pattern/input_pattern.rs index fa2af5e..d5e6c39 100644 --- a/src/pattern/input_pattern.rs +++ b/src/pattern/input_pattern.rs @@ -55,11 +55,11 @@ impl InputPattern { pub fn tree_to_preview(&self) -> Self { let regex_parts: Option<(String, String)> = match &self.pattern { Pattern::ContentExact(cp) => Some(cp.to_regex_parts()), - Pattern::ContentRegex(cp) => Some(cp.to_regex_parts()), + Pattern::ContentRegex(rp) => Some(rp.to_regex_parts()), Pattern::Composite(cp) => cp.expr .iter_atoms() .find_map(|p| match p { - Pattern::ContentExact(cp) => Some(cp.to_regex_parts()), + Pattern::ContentExact(ce) => Some(ce.to_regex_parts()), Pattern::ContentRegex(cp) => Some(cp.to_regex_parts()), _ => None }), -- cgit v1.2.3