Skip to content

csplit: don't strip \r before matching a regex - #15847

Merged
cakebaker merged 1 commit into
uutils:mainfrom
DevKaurav-14:fix/csplit-crlf-regex
Oct 26, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
DevKaurav-14:fix/csplit-crlf-regex

Conversation

@DevKaurav-14

Copy link
Copy Markdown
Contributor

Closes #15805

do_to_match stripped a trailing \r\n before testing a line against the pattern, so on CRLF input /^---$/ matched ---\r. GNU csplit (and grep/sed) treat that line as a non-match. It also meant a pattern that accounts for the \r, like /^---.$/, never matched.

Both match sites (positive and negative offset) now strip only the \n that LinesWithNewlines split on. Written pieces are unchanged.

Added two tests on x\n---\r\ny\n: one checks that /^---$/, /^---$/-1 and %^---$% report "match not found" with exit code 1 and leave no files, and one checks that /^---.$/, /^y$/-1 and /^---.$/+1 split where GNU does. I compared all six cases against GNU csplit 9.7 and the output, exit code and pieces match.

Note: this also changes behaviour for CRLF files on Windows, where $ no longer matches before the \r. That's consistent with GNU, but flagging it in case you want it handled differently.

@cakebaker
cakebaker merged commit e0056e3 into uutils:main Oct 26, 2026
100 of 101 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks for your PR!

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.

csplit: regex matching ignores the CR in CRLF lines, unlike GNU

3 participants