Skip to content

Fix empty regex matching with csvgrep any-match - #1372

Open
pauloflp wants to merge 1 commit into
wireservice:masterfrom
pauloflp:fix/csvgrep-empty-regex-20261027
Open

pauloflp wants to merge 1 commit into
wireservice:masterfrom
pauloflp:fix/csvgrep-empty-regex-20261027

Conversation

@pauloflp

Copy link
Copy Markdown

An explicitly supplied empty regex is valid and matches every value. csvgrep currently tests the argument's truthiness, falls through to a missing string pattern, and removes the pattern from its filters. As a result, csvgrep -a -c 1,2 -r '' examples/dummy.csv emits only the header, while adding -i incorrectly emits the data row.

Distinguish an absent regex (None) from an empty one and compile both empty and nonempty regexes through the same path. This keeps filtering semantics consistent between all/any-column matching and inversion. Includes four regression combinations and an Unreleased changelog entry. No new option or dependency.

Validation on Linux / Python 3.12.14:

  • Before the source fix, two new subtests fail (any-match with and without inversion).
  • csvgrep suite: 19 passed and 6 subtests passed.
  • Full suite: 351 passed, 4 skipped, 35 subtests passed; one existing failure in TestCSVStat.test_decimal_format (9748.346 vs 9,748.346), also reproduced on clean upstream base eefcd0ef72747ebf7e9086987ff267291ad877fa during this contribution session.
  • Changed-file flake8/isort and git diff --check pass.

AI-assisted implementation and local verification. Checked existing open PRs for duplicates.

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