From a2f7a58096e6dd7864835f18976d1e5e2f1462cc Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 3 Feb 2025 22:50:46 +0100 Subject: [PATCH] bugfix: expr: make index rule non-atomic (#511) --- docs/release-notes.md | 2 ++ src/expr/expr.pest | 2 +- src/expr/mod.rs | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 79b24a0..bb25261 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,8 @@ of `zizmor`. * Fixed a bug where `zizmor` would fail to parse composite actions with inputs/outputs that are missing descriptions (#502) +* Expressions that contain indices with non-semantic whitespace are now parsed + correctly (#511) ## v1.3.0 diff --git a/src/expr/expr.pest b/src/expr/expr.pest index ec4b161..2235523 100644 --- a/src/expr/expr.pest +++ b/src/expr/expr.pest @@ -73,7 +73,7 @@ null = { "null" } context = ${ (function_call | identifier) ~ (("." ~ (identifier | star)) | index)* } star = { "*" } identifier = @{ (ASCII_ALPHA | "_" | "-") ~ (ASCII_ALPHANUMERIC | "_" | "-")* } -index = { ("[" ~ (or_expr | star) ~ "]") } +index = !{ ("[" ~ (or_expr | star) ~ "]") } /// Function calls function_call = !{ identifier ~ "(" ~ (or_expr ~ ("," ~ or_expr)*)? ~ ")" } diff --git a/src/expr/mod.rs b/src/expr/mod.rs index 04bbb23..94e9718 100644 --- a/src/expr/mod.rs +++ b/src/expr/mod.rs @@ -527,6 +527,10 @@ mod tests { "foo()[0]", "fromJson(steps.runs.outputs.data).workflow_runs[0].id", multiline, + "'a' == 'b' && 'c' || 'd'", + "github.event['a']", + "github.event['a' == 'b']", + "github.event['a' == 'b' && 'c' || 'd']", ]; for case in cases {