Merge pull request #15029 from caesarxuchao/fix-14622

fix label selector parser in case no value (or only whitespaces) is specified after the key
This commit is contained in:
Alex Robinson 2015-10-05 11:24:15 -07:00
commit 0920a979c7
2 changed files with 11 additions and 2 deletions

View File

@ -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)
if tok == EndOfStringToken || tok == CommaToken {
s.Insert("")
return s, nil
}
tok, lit = p.consume(Values)
if tok == IdentifierToken {
s.Insert(lit)
return s, nil

View File

@ -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",
@ -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())
}
}