Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safety check incorrect for set comprehensions #377

Closed
tsandall opened this issue Jul 12, 2017 · 0 comments · Fixed by #378
Closed

Safety check incorrect for set comprehensions #377

tsandall opened this issue Jul 12, 2017 · 0 comments · Fixed by #378
Labels

Comments

@tsandall
Copy link
Member

It seems the safety check for set comprehensions is not working as expected.

> {k | a =[1,2,3]; a[k] }
2 errors occurred:
1:2: rego_unsafe_var_error: var k is unsafe
1:2: rego_unsafe_var_error: var a is unsafe

Whereas the following is OK:

> a=[1,2,3]; x = {k | a[k]}
+---------+---------+
|    a    |    x    |
+---------+---------+
| [1,2,3] | [0,1,2] |
+---------+---------+
@tsandall tsandall added the bug label Jul 12, 2017
mmussomele added a commit to mmussomele/opa that referenced this issue Jul 12, 2017
The grammar definition was ambigious to whether a lone Set Comprehension
was a Set Comprehension at all, instead parsing it as a Body. An example
is:
    `{k | a = [1, 2, 3]; a[k]}`

The parser would interpret this as a Body with the expressions
`[1, 2, 3] = k | a` and `a[k]`, which is not the intended result. To
resolve this, the parser now prioritizes `NonWhitespaceBody`s over
`BraceEnclosedBody`s in order to parse Set Comprehensions passed to
the REPL or as queries properly.

Fixes open-policy-agent#377

Co-Authored-By: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Jul 12, 2017
The grammar definition was ambigious to whether a lone Set Comprehension
was a Set Comprehension at all, instead parsing it as a Body. An example
is:
    `{k | a = [1, 2, 3]; a[k]}`

The parser would interpret this as a Body with the expressions
`[1, 2, 3] = k | a` and `a[k]`, which is not the intended result. To
resolve this, the parser now prioritizes `NonWhitespaceBody`s over
`BraceEnclosedBody`s in order to parse Set Comprehensions passed to
the REPL or as queries properly.

Fixes #377

Co-Authored-By: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant