mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 18:56:55 -06:00
Reject non-digit array indexes in batch step references
Found while testing crates/engine/src/steps.rs:74 (parse) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
62a9c5e240
commit
bd96665f44
@@ -111,6 +111,9 @@ fn parse(s: &str) -> Option<(Step, Vec<Seg>)> {
|
||||
rest = r;
|
||||
} else {
|
||||
let (n, r) = rest.strip_prefix('[')?.split_once(']')?;
|
||||
if n.is_empty() || !n.bytes().all(|b| b.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
path.push(Seg::Index(n.parse().ok()?));
|
||||
rest = r;
|
||||
}
|
||||
@@ -161,6 +164,16 @@ mod tests {
|
||||
assert!(e.contains("MB of values"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_index_must_be_plain_digits() {
|
||||
let results = [json!({"ids": [5, 6]})];
|
||||
assert_eq!(resolve(&json!("$0.ids[1]"), &results).unwrap(), json!(6));
|
||||
for s in ["$0.ids[+1]", "$0.ids[]", "$0.ids[ 1]", "$0.ids[-1]"] {
|
||||
let p = json!(s);
|
||||
assert!(resolve(&p, &results).map_or(true, |v| v == p), "{s}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_strings_and_escapes_are_left_alone() {
|
||||
let results = [json!({"id": 2})];
|
||||
|
||||
Reference in New Issue
Block a user