Skip to content

Commit

Permalink
Merge branch 'main' into catalog-2
Browse files Browse the repository at this point in the history
  • Loading branch information
eddycharly authored Oct 10, 2023
2 parents f3a8d6b + 88cbfdf commit 8a597e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ foo:
```

Here the `(bar)` key conflict with the projection syntax used.
To workaround this issue, you can escape a projection by surrounding it with `/` characters like this:
To workaround this issue, you can escape a projection by surrounding it with `\` characters like this:

```yaml
apiVersion: json.kyverno.io/v1alpha1
Expand All @@ -344,17 +344,17 @@ spec:
assert:
all:
- foo:
/(bar)/: 10
\(bar)\: 10
```

In this case, the leading and trailing `/` characters will be erased and the projection won't be applied.
In this case, the leading and trailing `\` characters will be erased and the projection won't be applied.

Note that it's still possible to use the `~` modifier or to create a named binding with and escaped projection.

Keys like this are perfectly valid:
- `~index./baz/`
- `/baz/@foo`
- `~index./baz/@foo`
- `~index.\baz\`
- `\baz\@foo`
- `~index.\baz\@foo`

## SDK

Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/assert/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var (
foreachRegex = regexp.MustCompile(`^~(\w+)?\.(.*)`)
bindingRegex = regexp.MustCompile(`(.*)@(\w+)$`)
escapeRegex = regexp.MustCompile(`^/(.+)/$`)
escapeRegex = regexp.MustCompile(`^\\(.+)\\$`)
engineRegex = regexp.MustCompile(`^\((?:(\w+):)?(.+)\)$`)
)

Expand Down
12 changes: 6 additions & 6 deletions pkg/engine/assert/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "/~(test)@foo/",
in: `\~(test)@foo\`,
want: &expression{
foreach: false,
foreachName: "",
Expand All @@ -124,7 +124,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "/test/",
in: `\test\`,
want: &expression{
foreach: false,
foreachName: "",
Expand All @@ -133,7 +133,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "/(test)/",
in: `\(test)\`,
want: &expression{
foreach: false,
foreachName: "",
Expand All @@ -142,7 +142,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "//test//",
in: `\/test/\`,
want: &expression{
foreach: false,
foreachName: "",
Expand All @@ -151,7 +151,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "~index./(test)/",
in: `~index.\(test)\`,
want: &expression{
foreach: true,
foreachName: "index",
Expand All @@ -160,7 +160,7 @@ func Test_parseExpressionRegex(t *testing.T) {
},
}, {
name: "escape",
in: "~index./(test)/@name",
in: `~index.\(test)\@name`,
want: &expression{
foreach: true,
foreachName: "index",
Expand Down
10 changes: 5 additions & 5 deletions testdata/escaped/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ spec:
assert:
all:
- foo:
/(bar)/: 4
\(bar)\: 4
- foo:
/(bar)/@test:
\(bar)\@test:
($test): 4
- foo:
/(bar)@test/: 6
\(bar)@test\: 6
- foo:
/(bar)@test/@test:
\(bar)@test\@test:
($test): 6
- foo:
/~foos/:
\~foos\:
- 1
- 2
- 3
12 changes: 6 additions & 6 deletions website/docs/policies/escaping.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ foo:
```
Here the `(bar)` key conflict with the projection syntax.
To workaround this situation, you can escape a projection by surrounding it with `/` characters like this:
To workaround this situation, you can escape a projection by surrounding it with `\` characters like this:

```yaml
apiVersion: json.kyverno.io/v1alpha1
Expand All @@ -28,15 +28,15 @@ spec:
assert:
all:
- foo:
/(bar)/: 10
\(bar)\: 10
```

In this case, the leading and trailing `/` characters will be erased and the projection won't be applied.
In this case, the leading and trailing `\` characters will be erased and the projection won't be applied.

Note that it's still possible to use the `~` modifier or to create a named binding with and escaped projection.

Keys like this are perfectly valid:

- `~index./baz/`
- `/baz/@foo`
- `~index./baz/@foo`
- `~index.\baz\`
- `\baz\@foo`
- `~index.\baz\@foo`

0 comments on commit 8a597e2

Please sign in to comment.