mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
parser: fix index out of bounds error (#4484)
+ revert 1bc9980
to use files in workspace
This commit is contained in:
parent
50a27e0aac
commit
e5b6f63305
2 changed files with 8 additions and 4 deletions
|
@ -11,10 +11,10 @@ cargo-fuzz = true
|
||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
|
|
||||||
[dependencies.uucore]
|
[dependencies.uucore]
|
||||||
uucore = { workspace = true }
|
path = "../src/uucore/"
|
||||||
|
|
||||||
[dependencies.uu_date]
|
[dependencies.uu_date]
|
||||||
uu_date = { workspace = true }
|
path = "../src/uu/date/"
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
# Prevent this from interfering with workspaces
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -10,8 +10,9 @@ fn fix_negation(glob: &str) -> String {
|
||||||
let mut chars = glob.chars().collect::<Vec<_>>();
|
let mut chars = glob.chars().collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < chars.len() {
|
// Add 3 to prevent out of bounds in loop
|
||||||
if chars[i] == '[' && i + 4 <= glob.len() && chars[i + 1] == '^' {
|
while i + 3 < chars.len() {
|
||||||
|
if chars[i] == '[' && chars[i + 1] == '^' {
|
||||||
match chars[i + 3..].iter().position(|x| *x == ']') {
|
match chars[i + 3..].iter().position(|x| *x == ']') {
|
||||||
None => (),
|
None => (),
|
||||||
Some(j) => {
|
Some(j) => {
|
||||||
|
@ -105,5 +106,8 @@ mod tests {
|
||||||
assert_eq!(fix_negation("[^]"), "[^]");
|
assert_eq!(fix_negation("[^]"), "[^]");
|
||||||
assert_eq!(fix_negation("[^"), "[^");
|
assert_eq!(fix_negation("[^"), "[^");
|
||||||
assert_eq!(fix_negation("[][^]"), "[][^]");
|
assert_eq!(fix_negation("[][^]"), "[][^]");
|
||||||
|
|
||||||
|
// Issue #4479
|
||||||
|
assert_eq!(fix_negation("ààà[^"), "ààà[^");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue