parser: fix index out of bounds error (#4484)

+ revert 1bc9980 to use files in workspace
This commit is contained in:
papparapa
2023-03-12 19:07:59 +09:00
committed by GitHub
parent 50a27e0aac
commit e5b6f63305
2 changed files with 8 additions and 4 deletions
+2 -2
View File
@@ -11,10 +11,10 @@ cargo-fuzz = true
libfuzzer-sys = "0.4"
[dependencies.uucore]
uucore = { workspace = true }
path = "../src/uucore/"
[dependencies.uu_date]
uu_date = { workspace = true }
path = "../src/uu/date/"
# Prevent this from interfering with workspaces
[workspace]
+6 -2
View File
@@ -10,8 +10,9 @@ fn fix_negation(glob: &str) -> String {
let mut chars = glob.chars().collect::<Vec<_>>();
let mut i = 0;
while i < chars.len() {
if chars[i] == '[' && i + 4 <= glob.len() && chars[i + 1] == '^' {
// Add 3 to prevent out of bounds in loop
while i + 3 < chars.len() {
if chars[i] == '[' && chars[i + 1] == '^' {
match chars[i + 3..].iter().position(|x| *x == ']') {
None => (),
Some(j) => {
@@ -105,5 +106,8 @@ mod tests {
assert_eq!(fix_negation("[^]"), "[^]");
assert_eq!(fix_negation("[^"), "[^");
assert_eq!(fix_negation("[][^]"), "[][^]");
// Issue #4479
assert_eq!(fix_negation("ààà[^"), "ààà[^");
}
}