Skip to content

fix(strings): ignore unnamed capture groups - #2770

Open
maximilize wants to merge 1 commit into
mikefarah:masterfrom
maximilize:fix/capture-unnamed-groups
Open

fix(strings): ignore unnamed capture groups#2770
maximilize wants to merge 1 commit into
mikefarah:masterfrom
maximilize:fix/capture-unnamed-groups

Conversation

@maximilize

Copy link
Copy Markdown
Contributor

Note: this PR was prepared by an AI agent (Claude Code) acting on behalf of @maximilize, not by the user personally.

what

capture emits unnamed regex groups as a map entry with an empty-string key, and produces duplicate empty keys when there are several:

echo 'foobar' | yq 'capture("(foo)(?P<rest>bar)")'
# before: '"": foo' then 'rest: bar'
# after:  'rest: bar'

Two unnamed groups (capture("(a)(b)") on ab) yield a mapping with two identical "" keys.

why

capture (pkg/yqlib/operator_strings.go) iterates over every submatch and unconditionally builds a key from regEx.SubexpNames(), which is "" for unnamed groups. jq only returns named capture groups, and string-operators.md documents capture as returning "named RegEx capture groups in a map".

fix

Skip submatches whose name is empty, matching jq. Regression scenario added (skipDoc).

capture() built a map key from SubexpNames() for every submatch; unnamed groups (name "") became an empty-string key (and duplicate keys for several). jq returns only named captures.
cymertek added a commit to cymertek/yq that referenced this pull request Jul 29, 2026
…hensive documentation

  ## Critical Bug Fixes (mikefarah#2786, mikefarah#2785, mikefarah#2769, mikefarah#2770, mikefarah#2771, mikefarah#2772)
  - Fixed missing keys in read-only context operations
  - Added negative array index support to `has()` function
  - Enhanced TOML comment roundtripping during decode/encode cycles
  - Added capture group support for XML/HTML regex parsing
  - Fixed integer overflow in sort operations
  - Corrected first operation returning key instead of value

  ## New Features
  - Added `--stdin-filename` flag for virtual filename context
  - Preserved large integers beyond JavaScript Number.MAX_SAFE_INTEGER in JSON output

  ## Crash & Memory Leak Fixes
  - **File handle leaks**: Added proper cleanup to operator_load.go, stream_evaluator.go, front_matter.go, printer_writer.go (MultiPrintWriter)
  - **Bounds checking**: Fixed index out of bounds in candidate_node.go FilterMapContentByKey and decoder_xml.go Content[0] access
  - **Panic prevention**: Enhanced TOML decoder recover() to always convert panics to errors, added EOF error logging

  ## Go Documentation & Conventions
  - Added GoDoc comments to 200+ exported symbols across all packages (golint: 0 warnings)
  - Removed all redundant `//nolint:golint` directives - proper documentation instead of suppression flags
  - Standardized naming conventions: URI, JSON, XML, LHS/RHS throughout codebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant