mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-21 17:15:35 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user