mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #6036 from cj-zoltan-kiss/zoltankiss/globfix
parser: if closing square bracket not found, stop looking for it again
This commit is contained in:
commit
93b1abff39
1 changed files with 10 additions and 1 deletions
|
@ -18,7 +18,11 @@ fn fix_negation(glob: &str) -> String {
|
||||||
while i + 3 < chars.len() {
|
while i + 3 < chars.len() {
|
||||||
if chars[i] == '[' && chars[i + 1] == '^' {
|
if chars[i] == '[' && chars[i + 1] == '^' {
|
||||||
match chars[i + 3..].iter().position(|x| *x == ']') {
|
match chars[i + 3..].iter().position(|x| *x == ']') {
|
||||||
None => (),
|
None => {
|
||||||
|
// if closing square bracket not found, stop looking for it
|
||||||
|
// again
|
||||||
|
break;
|
||||||
|
}
|
||||||
Some(j) => {
|
Some(j) => {
|
||||||
chars[i + 1] = '!';
|
chars[i + 1] = '!';
|
||||||
i += j + 4;
|
i += j + 4;
|
||||||
|
@ -90,6 +94,11 @@ mod tests {
|
||||||
assert_eq!(fix_negation("[[]] [^a]"), "[[]] [!a]");
|
assert_eq!(fix_negation("[[]] [^a]"), "[[]] [!a]");
|
||||||
assert_eq!(fix_negation("[[] [^a]"), "[[] [!a]");
|
assert_eq!(fix_negation("[[] [^a]"), "[[] [!a]");
|
||||||
assert_eq!(fix_negation("[]] [^a]"), "[]] [!a]");
|
assert_eq!(fix_negation("[]] [^a]"), "[]] [!a]");
|
||||||
|
|
||||||
|
// test that we don't look for closing square brackets unnecessarily
|
||||||
|
// Verifies issue #5584
|
||||||
|
let chars = std::iter::repeat("^[").take(174571).collect::<String>();
|
||||||
|
assert_eq!(fix_negation(chars.as_str()), chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue