sort: `-b` and `-M` still skip leading form feed and carriage return (follow-up to #14119)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The reported behavior is in src/uu/sort/src/sort.rs, in the -b key trimming and month_parse paths. Read those sections and the existing sort tests, then run the focused tests for blank trimming and month sorting. Done means form feed and carriage return are not skipped as blanks in the C locale, and the results match the reported GNU examples.
Written by the indexing model from the issue text.
Description
#14119 (closed by PR #15436) was about uutils sort treating \f and \r as blanks. After #15436, -n, -h, -d and default field splitting match GNU. Two places still skip a leading \f or \r: the leading-blank trimming of -b (global or -k N b) and the month parser of -M. In the C locale a blank is only a space or a tab.
The GNU manual (sort invocation) says:
-b: Ignore leading blanks when finding sort keys in each line. By default a blank is a space or a tab, but the LC_CTYPE locale can change this.
-M: An initial string, consisting of any amount of blanks, followed by a month name abbreviation, is folded to UPPER case and compared in the order 'JAN' < 'FEB' < ... < 'DEC'. Invalid names compare low to valid names. ... By default a blank is a space or a tab
printf 'a\n\fb\n' | sort -k1b | od -An -c
# GNU 9.12: \f b \n a \n (the key keeps its \f, and \f < a)
# uutils: a \n \f b \n (the \f was skipped, so "b" > "a")
printf '\rFEB\nJAN\n' | sort -M | od -An -c
# GNU 9.12: \r F E B \n J A N \n ("\rFEB" is not a month, so it sorts low)
# uutils: J A N \n \r F E B \n
\f and \r behave the same in both cases.
Versions. uutils main eee56033d28bf7ef5cc816286b048779d57fb803 (2026-10-21, includes #15436) and the 0.12.0 release binary, macOS 26 aarch64 (the loop found it on Linux x86_64), LC_ALL=C, compared with GNU coreutils 9.12.
Where. src/uu/sort/src/sort.rs: the -b key trimming uses is_ascii_whitespace (in the key-selection code around position(|c| !c.is_ascii_whitespace())), and month_parse starts with line.trim_ascii_start().
Related: #14119 and PR #15436 cover -n, -h, -d and field splitting.
Found with an automated differential tester that compares uutils with GNU 9.12.
Reproduction steps
export LC_ALL=C
printf 'a\n\fb\n' | sort -k1b | od -An -c
# GNU 9.12: \f b \n a \n
# uutils: a \n \f b \n
printf '\rFEB\nJAN\n' | sort -M | od -An -c
# GNU 9.12: \r F E B \n J A N \n
# uutils: J A N \n \r F E B \n
- Dominant language
- Rust
- Stars
- 24.3k
- Forks
- 2.1k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 331
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uutils/coreutils
-
U - sort
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
uutils/coreutils#15598 · 3 comments ·
Maintainers usually reply within 1 day
-
U - sort
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
uutils/coreutils#15596 · 3 comments ·
Maintainers usually reply within 1 day
-
U - sort
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
U - sort
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Maintainers usually reply within 1 day
-
nl: unnumbered lines are padded with width+1 spaces, ignoring the length of `-s`Possibly taken @cakebaker claimed this 1 day ago. OpenU - nl
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
All issues in uutils/coreutils
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
area:sim good first issue kind:feature
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
bitcoindevkit/bdk#2432 ·
Maintainers usually reply within 3 days
-
The demo's interval button and chart legend keep the previous interval after an interval changeOpenbug ui
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
userFRM/egui-charts#670 ·
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Usenova-Labs/usenova-backend#35 ·
Maintainers usually reply within 1 day