This commit is contained in:
maximilize 2026-07-06 10:40:48 +02:00 committed by GitHub
commit 083a9338a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -365,8 +365,14 @@ func capture(matchPrefs matchPreferences, regEx *regexp.Regexp, candidate *Candi
_, submatches := matches[0], matches[1:]
for j, submatch := range submatches {
keyNode := createScalarNode(subNames[j+1], subNames[j+1])
name := subNames[j+1]
// jq only returns named capture groups; unnamed groups (whose
// SubexpNames entry is "") must be skipped so they don't become
// map entries with an empty-string key.
if name == "" {
continue
}
keyNode := createScalarNode(name, name)
var valueNode *CandidateNode
offset := allIndices[i][2+j*2]

View File

@ -364,6 +364,15 @@ var stringsOperatorScenarios = []expressionScenario{
"D0, P[], (!!seq)::[\"1\", \"true\", \"null\", \"~\", cat, \"{an: object}\", \"[array, 2]\"]\n",
},
},
{
skipDoc: true,
description: "Capture ignores unnamed groups",
document: `foobar`,
expression: `capture("(foo)(?P<rest>bar)")`,
expected: []string{
"D0, P[], (!!map)::rest: bar\n",
},
},
}
func TestStringsOperatorScenarios(t *testing.T) {