mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
Merge 3a74b34bf1 into e2f1d5ccf7
This commit is contained in:
commit
083a9338a2
@ -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]
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user