Description
module.[select(.source | contains("docker_application"))] produces a syntax error:
{"error": "query_syntax", "message": "Invalid segment name before [select(): ''"}
The ~[select()] tilde syntax works correctly: module~[select(.source | contains("docker_application"))].
The simple .[] jq alias also works: module.[].
Root Cause
Two issues in hcl2/query/path.py:
-
Line 45 — The .[] jq alias replacement (path_str.replace(".[]", "[*]")) only handles the exact literal .[], not .[select(...)] or .[*].
-
Line 159 — _split_path() treats . as a segment separator without looking ahead. When . is immediately followed by [, it splits there, producing an empty segment name '' before the [select(...)] bracket. Then _extract_select() (line 211) validates seg_name = part[:0] → empty string → raises QuerySyntaxError.
Expected Behavior
module.[select(...)] should work the same as module~[select(...)] — the . before [ should be treated as jq-style bracket application, not as a path separator.
Workaround
Use the tilde syntax: module~[select(.source | contains("docker_application"))]
Suggested Fix
In _split_path(), when a . is immediately followed by [, don't treat it as a separator — either consume it as part of the bracket syntax or apply the same wildcard expansion that .[] gets. Existing tests for .[select()] patterns are missing in test/unit/query/test_path.py.
Description
module.[select(.source | contains("docker_application"))]produces a syntax error:The
~[select()]tilde syntax works correctly:module~[select(.source | contains("docker_application"))].The simple
.[]jq alias also works:module.[].Root Cause
Two issues in
hcl2/query/path.py:Line 45 — The
.[]jq alias replacement (path_str.replace(".[]", "[*]")) only handles the exact literal.[], not.[select(...)]or.[*].Line 159 —
_split_path()treats.as a segment separator without looking ahead. When.is immediately followed by[, it splits there, producing an empty segment name''before the[select(...)]bracket. Then_extract_select()(line 211) validatesseg_name = part[:0]→ empty string → raisesQuerySyntaxError.Expected Behavior
module.[select(...)]should work the same asmodule~[select(...)]— the.before[should be treated as jq-style bracket application, not as a path separator.Workaround
Use the tilde syntax:
module~[select(.source | contains("docker_application"))]Suggested Fix
In
_split_path(), when a.is immediately followed by[, don't treat it as a separator — either consume it as part of the bracket syntax or apply the same wildcard expansion that.[]gets. Existing tests for.[select()]patterns are missing intest/unit/query/test_path.py.