cut: fix -s flag ignored when delimiter is newline#10037
Closed
rynewang wants to merge 4 commits intouutils:mainfrom
Closed
cut: fix -s flag ignored when delimiter is newline#10037rynewang wants to merge 4 commits intouutils:mainfrom
rynewang wants to merge 4 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
When using newline as the delimiter (-d $'\n') with -s (only-delimited), cut should suppress lines that do not contain the delimiter. However, cut_fields_newline_char_delim() was not checking the only_delimited flag, causing it to always output even when -s was specified. The fix uses read_until() instead of split() to read segments. Unlike split(), read_until() includes the delimiter in the buffer when found, allowing us to detect whether a delimiter was actually present or if we just hit EOF. This commit: - Adds only_delimited parameter to cut_fields_newline_char_delim() - Uses read_until() to detect delimiter presence while reading - If no delimiter found and only_delimited is true, returns early - Adds test case for newline delimiter with -s flag Fixes uutils#10012
b9649a6 to
3e15738
Compare
sylvestre
reviewed
Jan 4, 2026
sylvestre
reviewed
Jan 4, 2026
- Use read_to_end + split instead of read_until loop - Use Vec<&[u8]> instead of Vec<Vec<u8>> (no extra allocations) - Rename found_delimiter to has_delimiter - Check has_delimiter before removing trailing empty segment - Only write trailing newline if we output something - Remove unused BufRead import - Add tests for edge cases: just newline, empty input
9a58d7b to
526b5d8
Compare
|
GNU testsuite comparison: |
sylvestre
reviewed
Jan 6, 2026
sylvestre
reviewed
Jan 6, 2026
Address PR review comments: - Replace read_to_end() with streaming DelimReader iterator - DelimReader uses read_until() and tracks delimiter per segment - Only collect selected fields, not entire input - Remove b"".as_slice() check (DelimReader doesn't create trailing empties) - Simplify output with split_first() join pattern
|
GNU testsuite comparison: |
Merging this PR will not alter performance
Comparing Footnotes
|
|
GNU testsuite comparison: |
This was referenced Feb 26, 2026
Contributor
|
Closing as it has been superseded by #11143. Anyway, thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using newline as the delimiter (
-d $'\n') with-s(only-delimited), cut should suppress lines that do not contain the delimiter. However,cut_fields_newline_char_delim()was not checking theonly_delimitedflag, causing it to always output even when-swas specified.The Bug
Changes
only_delimitedparameter tocut_fields_newline_char_delim()only_delimitedis true, returns early without output-sflagFixes #10012