Fix label selector parsing for consecutive commas

Allow parsing of expressions like 'x in (a,,)' by removing
unnecessary token consumption in parseIdentifiersList.

Previously, when encountering consecutive commas in selector
value lists, the parser would incorrectly consume an extra
comma token, causing 'expected identifier' errors.

This change removes the p.consume(Values) call on line 851
that was preventing proper handling of empty values in
selector lists while maintaining correct comma handling.

Added test cases like "x in (a,,)" to verify the fix works correctly.
This commit is contained in:
Xinyi Rong
2025-08-07 01:46:29 -07:00
parent 180b4ec2ad
commit d4f8bebda0
2 changed files with 15 additions and 1 deletions

View File

@@ -848,7 +848,6 @@ func (p *Parser) parseIdentifiersList() (sets.String, error) {
return s, nil
}
if tok2 == CommaToken {
p.consume(Values)
s.Insert("") // to handle ,, Double "" removed by StringSet
}
default: // it can be operator

View File

@@ -636,9 +636,24 @@ func TestSetSelectorParser(t *testing.T) {
{"x in (abc,)", internalSelector{
getRequirement("x", selection.In, sets.NewString("abc", ""), t),
}, true, true},
{"x in (abc,abc)", internalSelector{
getRequirement("x", selection.In, sets.NewString("abc"), t),
}, true, true},
{"x in ()", internalSelector{
getRequirement("x", selection.In, sets.NewString(""), t),
}, true, true},
{"x in (a,,)", internalSelector{
getRequirement("x", selection.In, sets.NewString("a", ""), t),
}, true, true},
{"x in (a,,,)", internalSelector{
getRequirement("x", selection.In, sets.NewString("a", ""), t),
}, true, true},
{"x in (a,,,,,,)", internalSelector{
getRequirement("x", selection.In, sets.NewString("a", ""), t),
}, true, true},
{"x in (a,,a,,a,,a,,)", internalSelector{
getRequirement("x", selection.In, sets.NewString("a", ""), t),
}, true, true},
{"x notin (abc,,def),bar,z in (),w", internalSelector{
getRequirement("bar", selection.Exists, nil, t),
getRequirement("w", selection.Exists, nil, t),