From ed23fb9054c4ae9c3848f18baef0bb911d4000b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Jun 2023 17:58:33 +0000 Subject: [PATCH] Upgrade regex and regex-syntax Bump regex from 1.7.3 to 1.9.1 Bumps [regex](https://github.com/rust-lang/regex) from 1.7.3 to 1.8.3. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com Bump regex-syntax from 0.6.29 to 0.7.2 Bumps [regex-syntax](https://github.com/rust-lang/regex) from 0.6.29 to 0.7.2. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/commits) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: regex-syntax dependency-type: direct:production update-type: version-update:semver-minor Supersedes: #1334 Supersedes: #1343 Signed-off-by: dependabot[bot] --- Cargo.lock | 33 +++++++++++++++++++++++++++------ Cargo.toml | 4 ++-- src/regex_helper.rs | 21 +++++++++++++-------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 604810f8c..285b832ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "aho-corasick" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -363,7 +372,7 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "bstr", "fnv", "log", @@ -690,20 +699,32 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +dependencies = [ + "aho-corasick 1.0.1", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" dependencies = [ - "aho-corasick", + "aho-corasick 1.0.1", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "rustix" diff --git a/Cargo.toml b/Cargo.toml index 397819634..7401154e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,8 @@ nu-ansi-term = "0.49" argmax = "0.3.1" ignore = "0.4.20" num_cpus = "1.16" -regex = "1.7.3" -regex-syntax = "0.6" +regex = "1.9.1" +regex-syntax = "0.7" ctrlc = "3.2" humantime = "2.1" globset = "0.4" diff --git a/src/regex_helper.rs b/src/regex_helper.rs index 877c927cb..98211fe26 100644 --- a/src/regex_helper.rs +++ b/src/regex_helper.rs @@ -3,7 +3,7 @@ use regex_syntax::ParserBuilder; /// Determine if a regex pattern contains a literal uppercase character. pub fn pattern_has_uppercase_char(pattern: &str) -> bool { - let mut parser = ParserBuilder::new().allow_invalid_utf8(true).build(); + let mut parser = ParserBuilder::new().utf8(false).build(); parser .parse(pattern) @@ -16,16 +16,18 @@ fn hir_has_uppercase_char(hir: &Hir) -> bool { use regex_syntax::hir::*; match hir.kind() { - HirKind::Literal(Literal::Unicode(c)) => c.is_uppercase(), - HirKind::Literal(Literal::Byte(b)) => char::from(*b).is_uppercase(), + HirKind::Literal(Literal(bytes)) => match std::str::from_utf8(&bytes) { + Ok(s) => s.chars().any(|c| c.is_uppercase()), + Err(_) => bytes.iter().any(|b| char::from(*b).is_uppercase()), + }, HirKind::Class(Class::Unicode(ranges)) => ranges .iter() .any(|r| r.start().is_uppercase() || r.end().is_uppercase()), HirKind::Class(Class::Bytes(ranges)) => ranges .iter() .any(|r| char::from(r.start()).is_uppercase() || char::from(r.end()).is_uppercase()), - HirKind::Group(Group { hir, .. }) | HirKind::Repetition(Repetition { hir, .. }) => { - hir_has_uppercase_char(hir) + HirKind::Capture(Capture { sub, .. }) | HirKind::Repetition(Repetition { sub, .. }) => { + hir_has_uppercase_char(sub) } HirKind::Concat(hirs) | HirKind::Alternation(hirs) => { hirs.iter().any(hir_has_uppercase_char) @@ -36,7 +38,7 @@ fn hir_has_uppercase_char(hir: &Hir) -> bool { /// Determine if a regex pattern only matches strings starting with a literal dot (hidden files) pub fn pattern_matches_strings_with_leading_dot(pattern: &str) -> bool { - let mut parser = ParserBuilder::new().allow_invalid_utf8(true).build(); + let mut parser = ParserBuilder::new().utf8(false).build(); parser .parse(pattern) @@ -56,7 +58,7 @@ fn hir_matches_strings_with_leading_dot(hir: &Hir) -> bool { HirKind::Concat(hirs) => { let mut hirs = hirs.iter(); if let Some(hir) = hirs.next() { - if hir.kind() != &HirKind::Anchor(Anchor::StartText) { + if hir.kind() != &HirKind::Look(Look::Start) { return false; } } else { @@ -64,7 +66,10 @@ fn hir_matches_strings_with_leading_dot(hir: &Hir) -> bool { } if let Some(hir) = hirs.next() { - hir.kind() == &HirKind::Literal(Literal::Unicode('.')) + match hir.kind() { + HirKind::Literal(Literal(bytes)) => bytes.starts_with(&[b'.']), + _ => false, + } } else { false }