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

fix label selector parser in case no value (or only whitespaces) is specified after the key #15029

Merged
merged 1 commit into from
Oct 5, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/labels/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,12 @@ func (p *Parser) parseIdentifiersList() (sets.String, error) {
// parseExactValue parses the only value for exact match style
func (p *Parser) parseExactValue() (sets.String, error) {
s := sets.NewString()
tok, lit := p.consume(Values)
tok, lit := p.lookahead(Values)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases added

if tok == EndOfStringToken || tok == CommaToken {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the tok == CommaToken case at first.

s.Insert("")
return s, nil
}
tok, lit = p.consume(Values)
if tok == IdentifierToken {
s.Insert(lit)
return s, nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/labels/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func TestSelectorParse(t *testing.T) {
"x=a,y=b,z=c",
"",
"x!=a,y=b",
"x=",
"x= ",
"x=,z= ",
"x= ,z= ",
}
testBadStrings := []string{
"x=a||y=b",
Expand All @@ -39,7 +43,7 @@ func TestSelectorParse(t *testing.T) {
if err != nil {
t.Errorf("%v: error %v (%#v)\n", test, err, err)
}
if test != lq.String() {
if strings.Replace(test, " ", "", -1) != lq.String() {
t.Errorf("%v restring gave: %v\n", test, lq.String())
}
}
Expand Down