mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-14 12:22:51 -06:00
fix: don't panic on format due to unexpected comments (#7458)
fix: don't panic on format due to unexpected comments comments next to object elements is valid rego, instead of panicking catch the error and write the rule as-is. Signed-off-by: sspaink <sspaink@styra.com>
This commit is contained in:
+688
-209
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
package a
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"} # test 2
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"}
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p.foo.bar[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
][
|
||||
{"c": #
|
||||
"d"} #
|
||||
] := true
|
||||
@@ -0,0 +1,31 @@
|
||||
package a
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"} # test 2
|
||||
|
||||
value := {"a": "b"} # test 1
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
p[{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p.foo.bar[{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p[{"a": #
|
||||
"b"} #
|
||||
][{"c": #
|
||||
"d"} #
|
||||
] := true
|
||||
@@ -0,0 +1,6 @@
|
||||
package a
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
@@ -0,0 +1,6 @@
|
||||
package a
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
@@ -0,0 +1,135 @@
|
||||
package a
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"} # test 2
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"}
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
|
||||
p := {"a": #
|
||||
"b"} if { #
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
value := {"a":
|
||||
{"b":
|
||||
{"c":
|
||||
"d"}}}
|
||||
|
||||
f(_) := value if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
|
||||
p := value if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
|
||||
p := x if {
|
||||
x := [v | v := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
]
|
||||
}
|
||||
|
||||
p if {
|
||||
every x in input.foo {
|
||||
x == {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
}
|
||||
|
||||
value contains {"a": #
|
||||
"b"} #
|
||||
|
||||
p := {"a": #
|
||||
str} if {
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
p := {"a":
|
||||
str} if {
|
||||
#
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
authorize := "allow" if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
input.user == "superuser" # allow 'superuser' to perform any operation.
|
||||
} else := "deny" if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
input.path[0] == value # disallow 'admin' operations...
|
||||
input.source_network == "external" # from external networks.
|
||||
} # ... more rules
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p.foo.bar[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
][
|
||||
{"c": #
|
||||
"d"} #
|
||||
] := true
|
||||
|
||||
p if {
|
||||
x := {"a": # do
|
||||
"b"} # re
|
||||
1 + 2 == 3
|
||||
y := {"c": # mi
|
||||
"d"} # fa
|
||||
x != y
|
||||
}
|
||||
|
||||
p[x].r := y if {
|
||||
x := "q"
|
||||
y := 1
|
||||
y := {"c": # hello
|
||||
"d"} # world
|
||||
|
||||
|
||||
|
||||
y := 1
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package a
|
||||
|
||||
p[{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
value := {"a": # test 1
|
||||
"b"} # test 2
|
||||
|
||||
value := {"a": "b"} # test 1
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
|
||||
p := {"a": #
|
||||
"b"} if { #
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
value := {"a": {"b": {"c": "d"}}}
|
||||
|
||||
f(_) := value if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
|
||||
p := value if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
|
||||
p := x if {
|
||||
x := [v | v := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
]
|
||||
}
|
||||
|
||||
p if {
|
||||
every x in input.foo {
|
||||
x == {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
}
|
||||
}
|
||||
|
||||
value contains {"a": #
|
||||
"b"} #
|
||||
|
||||
p := {"a": str} if { #
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
p := {"a": str} if {
|
||||
#
|
||||
str := "my \n string"
|
||||
}
|
||||
|
||||
authorize := "allow" if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
input.user == "superuser" # allow 'superuser' to perform any operation.
|
||||
} else := "deny" if {
|
||||
value := {"a": # this is
|
||||
{"b": # my ridiculous
|
||||
{"c": # way of
|
||||
"d"}}} # commenting code
|
||||
input.path[0] == value # disallow 'admin' operations...
|
||||
input.source_network == "external" # from external networks.
|
||||
} # ... more rules
|
||||
|
||||
p[{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p.foo.bar[{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
|
||||
p[{"a": #
|
||||
"b"} #
|
||||
][{"c": #
|
||||
"d"} #
|
||||
] := true
|
||||
|
||||
p if {
|
||||
x := {"a": # do
|
||||
"b"} # re
|
||||
1 + 2 == 3
|
||||
y := {"c": # mi
|
||||
"d"} # fa
|
||||
x != y
|
||||
}
|
||||
|
||||
p[x].r := y if {
|
||||
x := "q"
|
||||
y := 1
|
||||
y := {"c": # hello
|
||||
"d"} # world
|
||||
|
||||
y := 1
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
# A ref-head rule by itself is formatted differently when there are multiple ref-head rules in a file.
|
||||
# This file handles the case when there is a single ref-head rule, while `test_issue_6330.rego` handles multiple.
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
# A ref-head rule by itself is formatted differently when there are multiple ref-head rules in a file.
|
||||
# This file handles the case when there is a single ref-head rule, while `test_issue_6330.rego` handles multiple.
|
||||
|
||||
p[
|
||||
{"a": #
|
||||
"b"} #
|
||||
] := true
|
||||
Reference in New Issue
Block a user