Skip to content

cut: trim Unicode blanks with -w=trimmed - #15832

Open
sarankumar1325 wants to merge 1 commit into
uutils:mainfrom
sarankumar1325:fix/cut-trimmed-unicode-blanks
Open

sarankumar1325 wants to merge 1 commit into
uutils:mainfrom
sarankumar1325:fix/cut-trimmed-unicode-blanks

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Fixes #15819.

In a UTF-8 locale, WhitespaceMatcher splits fields on Unicode blanks such as U+3000, but cut_fields_whitespace_trimmed trimmed the ends of each line with a byte test that only knows SPACE and TAB. A leading Unicode blank therefore survived trimming and became a delimiter, which emptied field 1. A trailing one added an empty last field, and -s stopped dropping one-word lines:

$ printf '\343\200\200shutdown now\n' | LC_ALL=C.UTF-8 cut -w=trimmed -f1

$

The ends are now trimmed with the same WhitespaceMatcher that splits the fields: a blank run at offset 0 is skipped, and a blank run that ends at the end of the line is dropped. In the C locale the matcher only sees SPACE/TAB through its memchr2 fast path, so output there is unchanged.

The -w help text in en-US.ftl still said "Space/Tab", so it now mentions Unicode spaces in a UTF-8 locale.

Tests

  • New test_whitespace_delimited_trimmed_unicode_blanks: leading U+3000, mixed leading/trailing SPACE + U+3000/U+2003, and -s with a one-word line padded by U+3000. It fails on main and passes with this change.
  • cargo test --features cut --no-default-features test_cut: 81 passed; cargo test -p uu_cut: 22 passed.
  • cargo fmt --check -p uu_cut and cargo clippy -p uu_cut --all-targets -- -D warnings are clean.

I used an AI assistant while working on this; I reviewed the change and the tests myself.

In a UTF-8 locale the whitespace matcher splits fields on Unicode blanks
such as U+3000, but -w=trimmed only stripped SPACE and TAB from the ends
of a line. A leading Unicode blank then emptied field 1 and shifted every
word, a trailing one added an empty last field, and -s kept one-word
lines. Trim with the same matcher that splits the fields, and update the
help text, which still said Space/Tab only.

Fixes uutils#15819
Copilot AI balanced review requested due to automatic review settings October 25, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
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.

cut: -w trimmed does not trim Unicode blanks, shifting fields by one

2 participants