Repository: Canop/broot (language: rust)

Issue:
Panic when previewing seemingly innocent JavaScript text file
broot 1.44.3 via Homebrew

```shellsession
$ echo 'export default new Map();' > test.js
$ broot test.js
thread 'main' panicked at /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/index.crates.io-6f17d22bba15001f/syntect-no-panic-4.6.1/src/parsing/regex.rs:69:53:
regex string should be pre-tested: InvalidEscape("\\g")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```


Discussion / hints:
Damn.

This is in syntect again, which I had already forked to patch a previous case of uncatched panic.

I'll have a look.
(reference: https://github.com/Canop/broot/issues/485)

Trying to use syntect 5

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index f821d072..ab874145 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -293,7 +293,7 @@ dependencies = [
 
 [[package]]
 name = "broot"
-version = "1.44.3"
+version = "1.44.4-dev"
 dependencies = [
  "ansi_colours",
  "base64 0.21.7",
@@ -335,7 +335,7 @@ dependencies = [
  "smallvec",
  "splitty",
  "strict 0.1.4",
- "syntect-no-panic",
+ "syntect-5-no-panic",
  "tempfile",
  "termimad 0.31.1",
  "terminal-clipboard",
@@ -888,9 +888,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
 
 [[package]]
 name = "fancy-regex"
-version = "0.7.1"
+version = "0.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d6b8560a05112eb52f04b00e5d3790c0dd75d9d980eb8a122fb23b92a623ccf"
+checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
 dependencies = [
  "bit-set",
  "regex",
@@ -2281,7 +2281,7 @@ dependencies = [
  "aho-corasick",
  "memchr",
  "regex-automata",
- "regex-syntax 0.8.5",
+ "regex-syntax",
 ]
 
 [[package]]
@@ -2292,15 +2292,9 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
 dependencies = [
  "aho-corasick",
  "memchr",
- "regex-syntax 0.8.5",
+ "regex-syntax",
 ]
 
-[[package]]
-name = "regex-syntax"
-version = "0.6.29"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
-
 [[package]]
 name = "regex-syntax"
 version = "0.8.5"
@@ -2678,23 +2672,23 @@ dependencies = [
 ]
 
 [[package]]
-name = "syntect-no-panic"
-version = "4.6.1"
+name = "syntect-5-no-panic"
+version = "5.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bee6d840027be11d9fae1432a799c548eaf0332a9a8dbe8526281d55a9600e4f"
+checksum = "3ff30a7ee8b54eddf236a96441915a2a47dc2d5e093cf2e347588962a522ef88"
 dependencies = [
  "bincode",
  "bitflags 1.3.2",
  "fancy-regex",
  "flate2",
  "fnv",
- "lazy_static",
  "once_cell",
  "plist",
- "regex-syntax 0.6.29",
+ "regex-syntax",
  "serde",
  "serde_derive",
  "serde_json",
+ "thiserror",
  "walkdir",
  "yaml-rust",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index 4049a9fb..8e6fba7f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "broot"
-version = "1.44.3"
+version = "1.44.4-dev"
 authors = ["dystroy <denys.seguret@gmail.com>"]
 repository = "https://github.com/Canop/broot"
 homepage = "https://dystroy.org/broot"
@@ -57,7 +57,7 @@ serde = { version = "1.0", features = ["derive"] }
 smallvec = "1.11" # version 2 is still alpha
 splitty = "1.0.2"
 strict = "0.1.4"
-syntect = { package = "syntect-no-panic", version = "4.6.1", default-features = false, features = ["default-fancy"] } # see issues #485 and #956
+syntect = { package = "syntect-5-no-panic", version = "5.2", default-features = false, features = ["default-fancy"] } # see issues #485, #956, #967
 tempfile = "3.2"
 termimad = "0.31"
 terminal-clipboard = { version = "0.4.1", optional = true }
@@ -118,8 +118,7 @@ harness = false
 # lfs-core = { path = "../lfs-core" }
 # minimad = { path = "../minimad" }
 # secular = { path = "../secular", features=["normalization"] }
-# syntect = { path = "../syntect" }
-# syntect-no-panic = { path = "../syntect" }
+# syntect-5-no-panic = { path = "../syntect" }
 # termimad = { path = "../termimad" }
 # terminal-clipboard = { path = "../terminal-clipboard" }
 # terminal-light = { path = "../terminal-light" }
diff --git a/resources/syntect/README.md b/resources/syntect/README.md
index e77e51f3..feec90b4 100644
--- a/resources/syntect/README.md
+++ b/resources/syntect/README.md
@@ -9,4 +9,4 @@ The [bat](https://github.com/sharkdp/bat) project maintains with care an importa
 
 It's the best public list I found, so I've included the resulting syntax set here as `syntaxes.bin`.
 
-You may replace this file with your own, building it with Syntect's [`syntect::dumps::dump_to_file`](https://docs.rs/syntect/4.6.0/syntect/dumps/fn.dump_to_file.html) function.
+You may replace this file with your own, building it with Syntect's [`syntect::dumps::dump_to_uncompressed_file`](https://docs.rs/syntect/latest/syntect/dumps/fn.dump_to_uncompressed_file.html) function.
diff --git a/resources/syntect/syntaxes.bin b/resources/syntect/syntaxes.bin
index 9bd09ea9..7a5cd310 100644
Binary files a/resources/syntect/syntaxes.bin and b/resources/syntect/syntaxes.bin differ
diff --git a/src/syntactic/syntactic_view.rs b/src/syntactic/syntactic_view.rs
index 12cc168e..c82fc1e4 100644
--- a/src/syntactic/syntactic_view.rs
+++ b/src/syntactic/syntactic_view.rs
@@ -174,8 +174,8 @@ impl SyntacticView {
             // Those chars are removed on printing
             let name_match = pattern.search_string(&line);
             let regions = if let Some(highlighter) = highlighter.as_mut() {
-                highlighter
-                    .highlight(&line, &SYNTAXER.syntax_set)
+                    highlighter
+                        .highlight_line(&line, &SYNTAXER.syntax_set)
                     .map_err(|e| ProgramError::SyntectCrashed { details: e.to_string() })?
                     .iter()
                     .map(Region::from_syntect)
diff --git a/src/syntactic/syntaxer.rs b/src/syntactic/syntaxer.rs
index 37d3e32f..2aa2a135 100644
--- a/src/syntactic/syntaxer.rs
+++ b/src/syntactic/syntaxer.rs
@@ -23,7 +23,10 @@ pub struct Syntaxer {
 impl Default for Syntaxer {
     fn default() -> Self {
         Self {
-            syntax_set: time!(Debug, syntect::dumps::from_binary(SYNTAXES)),
+            syntax_set: time!(
+                Debug,
+                syntect::dumps::from_uncompressed_data(SYNTAXES).unwrap()
+            ),
             theme_set: ThemeSet::load_defaults(),
         }
     }


Test patch: