mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
format: Fix dropped with-clause after comment in object value (#8785)
resolve: https://github.com/open-policy-agent/opa/issues/8765 Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
This commit is contained in:
+7
-1
@@ -1212,7 +1212,13 @@ func (w *writer) writeWith(with *ast.With, comments []*ast.Comment, indented boo
|
||||
w.write(" as ")
|
||||
comments, err = w.writeTerm(with.Value, comments)
|
||||
if err != nil {
|
||||
return comments, err
|
||||
// An unexpectedCommentError from writeTerm signals that it fell
|
||||
// back to writing the term's original unformatted text — the value
|
||||
// was written successfully, so don't abort the surrounding chain
|
||||
// of `with` clauses (issue #8765).
|
||||
if !errors.As(err, &unexpectedCommentError{}) {
|
||||
return comments, err
|
||||
}
|
||||
}
|
||||
return comments, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
test_x if {
|
||||
r := allow with input as {
|
||||
"a": "b", # a comment
|
||||
}
|
||||
with opa.runtime as {"env": {"E": "PROD"}}
|
||||
r == false
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
test_x if {
|
||||
r := allow with input as {
|
||||
"a": "b", # a comment
|
||||
}
|
||||
with opa.runtime as {"env": {"E": "PROD"}}
|
||||
r == false
|
||||
}
|
||||
Reference in New Issue
Block a user