Skip to content

Commit

Permalink
Dash should consider as field instead of separator
Browse files Browse the repository at this point in the history
Signed-off-by: Vaishnavi Vejella <vvejella@amazon.com>
  • Loading branch information
vvejell1 committed Oct 25, 2022
1 parent 1e6523f commit 6efbbb9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion filters/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := <go string syntax>
Expand Down
2 changes: 1 addition & 1 deletion filters/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions filters/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "=="},
Expand All @@ -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},
},
},
{
Expand Down

0 comments on commit 6efbbb9

Please sign in to comment.