diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /vendor/gix-glob/src/parse.rs | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-glob/src/parse.rs')
-rw-r--r-- | vendor/gix-glob/src/parse.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/vendor/gix-glob/src/parse.rs b/vendor/gix-glob/src/parse.rs index 665f459b9..368cf77c5 100644 --- a/vendor/gix-glob/src/parse.rs +++ b/vendor/gix-glob/src/parse.rs @@ -6,22 +6,26 @@ use crate::{pattern, pattern::Mode}; /// A sloppy parser that performs only the most basic checks, providing additional information /// using `pattern::Mode` flags. /// +/// If `may_alter` is `false`, we won't parse leading `!` or its escaped form. +/// /// Returns `(pattern, mode, no_wildcard_len)` -pub fn pattern(mut pat: &[u8]) -> Option<(&[u8], pattern::Mode, Option<usize>)> { +pub fn pattern(mut pat: &[u8], may_alter: bool) -> Option<(&[u8], pattern::Mode, Option<usize>)> { let mut mode = Mode::empty(); if pat.is_empty() { return None; }; - if pat.first() == Some(&b'!') { - mode |= Mode::NEGATIVE; - pat = &pat[1..]; - } else if pat.first() == Some(&b'\\') { - let second = pat.get(1); - if second == Some(&b'!') || second == Some(&b'#') { + if may_alter { + if pat.first() == Some(&b'!') { + mode |= Mode::NEGATIVE; pat = &pat[1..]; + } else if pat.first() == Some(&b'\\') { + let second = pat.get(1); + if second == Some(&b'!') || second == Some(&b'#') { + pat = &pat[1..]; + } } } - if pat.iter().all(|b| b.is_ascii_whitespace()) { + if pat.iter().all(u8::is_ascii_whitespace) { return None; } if pat.first() == Some(&b'/') { |