Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
terminal: Prevent `[]` from being sanitized into clickable file link (#20386)
Finn Eversf6d4a73c344d
diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rsindex 0b3e341485c..c03af8d48e6 100644--- a/crates/terminal/src/terminal.rs+++ b/crates/terminal/src/terminal.rs@@ -924,18 +924,22 @@ impl Terminal {} else if let Some(word_match) = regex_match_at(term, point, &mut self.word_regex) {let file_path = term.bounds_to_string(*word_match.start(), *word_match.end());- let (sanitized_match, sanitized_word) =- if file_path.starts_with('[') && file_path.ends_with(']') {- (- Match::new(- word_match.start().add(term, Boundary::Cursor, 1),- word_match.end().sub(term, Boundary::Cursor, 1),- ),- file_path[1..file_path.len() - 1].to_owned(),- )- } else {- (word_match, file_path)- };+ let (sanitized_match, sanitized_word) = if file_path.starts_with('[')+ && file_path.ends_with(']')+ // this is to avoid sanitizing the match '[]' to an empty string,+ // which would be considered a valid navigation target+ && file_path.len() > 2+ {+ (+ Match::new(+ word_match.start().add(term, Boundary::Cursor, 1),+ word_match.end().sub(term, Boundary::Cursor, 1),+ ),+ file_path[1..file_path.len() - 1].to_owned(),+ )+ } else {+ (word_match, file_path)+ };Some((sanitized_word, false, sanitized_match))} else {