From 6efbbb9856e50d5039812ca90d6f49b747a86b71 Mon Sep 17 00:00:00 2001 From: Vaishnavi Vejella Date: Thu, 13 Oct 2022 20:24:40 +0000 Subject: [PATCH] Dash should consider as field instead of separator Signed-off-by: Vaishnavi Vejella --- filters/parser.go | 2 +- filters/scanner.go | 2 +- filters/scanner_test.go | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/filters/parser.go b/filters/parser.go index 49182d7b7bd60..fafe9a15e7530 100644 --- a/filters/parser.go +++ b/filters/parser.go @@ -41,7 +41,7 @@ The formal grammar is as follows: selectors := selector ("," selector)* selector := fieldpath (operator value) fieldpath := field ('.' field)* -field := quoted | [A-Za-z] [A-Za-z0-9_]+ +field := quoted | [A-Za-z-] [A-Za-z0-9_-]+ operator := "==" | "!=" | "~=" value := quoted | [^\s,]+ quoted := diff --git a/filters/scanner.go b/filters/scanner.go index 6a485467b8a03..828b64f241b62 100644 --- a/filters/scanner.go +++ b/filters/scanner.go @@ -249,7 +249,7 @@ func digitVal(ch rune) int { } func isFieldRune(r rune) bool { - return (r == '_' || isAlphaRune(r) || isDigitRune(r)) + return (r == '-' || r == '_' || isAlphaRune(r) || isDigitRune(r)) } func isAlphaRune(r rune) bool { diff --git a/filters/scanner_test.go b/filters/scanner_test.go index b0e98fd5c105e..cf821a708e133 100644 --- a/filters/scanner_test.go +++ b/filters/scanner_test.go @@ -66,7 +66,7 @@ func TestScanner(t *testing.T) { }, { name: "SelectorsWithFieldPaths", - input: "name==value,labels.foo=value,other.bar~=match", + input: "name==value,labels.foo=value,other.bar~=match,labels.io-foo==value,labels.-io-foo==value", expected: []tokenResult{ {pos: 0, token: tokenField, text: "name"}, {pos: 4, token: tokenOperator, text: "=="}, @@ -83,7 +83,19 @@ func TestScanner(t *testing.T) { {pos: 35, token: tokenField, text: "bar"}, {pos: 38, token: tokenOperator, text: "~="}, {pos: 40, token: tokenValue, text: "match"}, - {pos: 45, token: tokenEOF}, + {pos: 45, token: tokenSeparator, text: ","}, + {pos: 46, token: tokenField, text: "labels"}, + {pos: 52, token: tokenSeparator, text: "."}, + {pos: 53, token: tokenField, text: "io-foo"}, + {pos: 59, token: tokenOperator, text: "=="}, + {pos: 61, token: tokenValue, text: "value"}, + {pos: 66, token: tokenSeparator, text: ","}, + {pos: 67, token: tokenField, text: "labels"}, + {pos: 73, token: tokenSeparator, text: "."}, + {pos: 74, token: tokenField, text: "-io-foo"}, + {pos: 81, token: tokenOperator, text: "=="}, + {pos: 83, token: tokenValue, text: "value"}, + {pos: 88, token: tokenEOF}, }, }, {