terminal: Fix hyperlinks not being detected correctly when preceded by box-drawing chars (#48447)

Yao Xiao created

Closes #46795

This PR aims to correctly detect the hyperlinks in cases like the
following, where box-drawing characters immediately precede the path
(without spaces in between).

```
╭─[Cargo.toml:55:1]
...
╰────
```

The only false negative with the fix in this PR would be that a file
path really contains leading box drawing characters which I think is
very unlikely.

---

Release Notes:

- Fixed an issue where the hyperlinks would not be properly detected in
the terminal if they were preceded by box-drawing characters (like ─, │,
┌, ┐)

Signed-off-by: Charlie-XIAO <yx2436@nyu.edu>

Change summary

assets/settings/default.json               |  8 ++++----
crates/terminal/src/terminal_hyperlinks.rs | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)

Detailed changes

assets/settings/default.json 🔗

@@ -1797,15 +1797,15 @@
         "(?x)",
         "(?<path>",
         "    (",
-        "        # multi-char path: first char (not opening delimiter or space)",
-        "        [^({\\[<\"'`\\ ]",
+        "        # multi-char path: first char (not opening delimiter, space, or box drawing char)",
+        "        [^({\\[<\"'`\\ \\u2500-\\u257F]",
         "        # middle chars: non-space, and colon/paren only if not followed by digit/paren",
         "        ([^\\ :(]|[:(][^0-9()])*",
         "        # last char: not closing delimiter or colon",
         "        [^()}\\]>\"'`.,;:\\ ]",
         "    |",
-        "        # single-char path: not delimiter, punctuation, or space",
-        "        [^(){}\\[\\]<>\"'`.,;:\\ ]",
+        "        # single-char path: not delimiter, punctuation, space, or box drawing char",
+        "        [^(){}\\[\\]<>\"'`.,;:\\ \\u2500-\\u257F]",
         "    )",
         "    # optional line/column suffix (included in path for PathWithPosition::parse_str)",
         "    (:+[0-9]+(:[0-9]+)?|:?\\([0-9]+([,:]?[0-9]+)?\\))?",

crates/terminal/src/terminal_hyperlinks.rs 🔗

@@ -905,6 +905,23 @@ mod tests {
                 );
             }
 
+            #[test]
+            // <https://github.com/zed-industries/zed/issues/46795>
+            fn issue_46795() {
+                // Box drawing characters are commonly used as UI elements and
+                // should not interfere with path detection; they appear rarely
+                // enough in actual paths that false positives should be minimal
+
+                test_path!("─‹«/👉test/cool.rs»:«4»:«2»›");
+                test_path!("┤‹«/👉test/cool.rs»:«4»:«2»›");
+                test_path!("╿‹«/👉test/cool.rs»:«4»:«2»›");
+
+                test_path!("└──‹«/👉test/cool.rs»:«4»:«2»›");
+                test_path!("├─[‹«/👉test/cool.rs»:«4»:«2»›]");
+                test_path!("─[‹«/👉test/cool.rs»:«4»:«2»›]");
+                test_path!("┬‹«/👉test/cool.rs»:«4»:«2»›┬");
+            }
+
             #[test]
             #[cfg_attr(
                 not(target_os = "windows"),