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

Support UTF-8 label matchers: Do not allow unquoted escape sequences #3571

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions matchers/compat/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestFallbackMatcherParser(t *testing.T) {
expected: mustNewMatcher(t, labels.MatchEqual, "foo🙂", "bar"),
}, {
name: "is accepted in old parser but not new",
input: "foo=!bar",
expected: mustNewMatcher(t, labels.MatchEqual, "foo", "!bar"),
input: "foo=!bar\\n",
expected: mustNewMatcher(t, labels.MatchEqual, "foo", "!bar\n"),
}, {
name: "is accepted in neither",
input: "foo!bar",
Expand Down Expand Up @@ -81,10 +81,10 @@ func TestFallbackMatchersParser(t *testing.T) {
},
}, {
name: "is accepted in old parser but not new",
input: "{foo=!bar,bar=$baz}",
input: "{foo=!bar,bar=$baz\\n}",
expected: labels.Matchers{
mustNewMatcher(t, labels.MatchEqual, "foo", "!bar"),
mustNewMatcher(t, labels.MatchEqual, "bar", "$baz"),
mustNewMatcher(t, labels.MatchEqual, "bar", "$baz\n"),
},
}, {
name: "is accepted in neither",
Expand Down
3 changes: 3 additions & 0 deletions matchers/compliance/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestCompliance(t *testing.T) {
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\\t")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar\t}`,
Expand All @@ -84,6 +85,7 @@ func TestCompliance(t *testing.T) {
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\\t")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar\}`,
Expand All @@ -92,6 +94,7 @@ func TestCompliance(t *testing.T) {
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\\")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar\\}`,
Expand Down
2 changes: 1 addition & 1 deletion matchers/parse/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
)

func isReserved(r rune) bool {
return unicode.IsSpace(r) || strings.ContainsRune("{}!=~,\"'`", r)
return unicode.IsSpace(r) || strings.ContainsRune("{}!=~,\\\"'`", r)
}

// expectedError is returned when the next rune does not match what is expected.
Expand Down
4 changes: 4 additions & 0 deletions matchers/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func TestMatchers(t *testing.T) {
name: "invalid escape sequence",
input: "{foo=\"bar\\w\"}",
error: "5:12: \"bar\\w\": invalid input",
}, {
name: "no unquoted escape sequences",
input: "{foo=bar\\n}",
error: "8:9: \\: invalid input: expected a comma or close brace",
}}

for _, test := range tests {
Expand Down
Loading