Skip to content

fix(builtins): sort -n extracts leading numeric prefix from strings#838

Merged
chaliy merged 2 commits intomainfrom
fix/issue-833-sort-numeric-prefix
Mar 26, 2026
Merged

fix(builtins): sort -n extracts leading numeric prefix from strings#838
chaliy merged 2 commits intomainfrom
fix/issue-833-sort-numeric-prefix

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 26, 2026

Summary

  • sort -n now parses the leading numeric portion of strings (e.g. 0003-msg.md → 3) instead of requiring the entire token to be a valid number
  • Adds full-line fallback comparison when sort keys are equal, fixing field-based sorting (-t/-k) when keys tie
  • Adds 7 new spec tests covering numeric prefix extraction, mixed prefix lengths, non-numeric-as-zero, field-based delimiter sorting, reverse numeric, and zero-padded numbers

Test plan

  • New spec tests pass: sort_numeric_prefix_strings, sort_numeric_mixed_prefix_lengths, sort_numeric_nonnumeric_as_zero, sort_field_delim_k2, sort_field_delim_k1, sort_numeric_reverse, sort_numeric_zero_padded
  • All existing sort/uniq spec tests still pass
  • cargo fmt --check clean
  • cargo clippy -p bashkit -- -D warnings clean

Closes #833

chaliy added 2 commits March 26, 2026 16:51
sort -n now parses the leading numeric portion of strings (like
0003-msg.md → 3) instead of requiring the entire token to be a number.
Also adds full-line fallback comparison when sort keys are equal, fixing
field-based sorting with -t/-k when keys tie.

Closes #833
cargo-vet exemption updated from 1.13.1 to 1.13.2 to match lockfile.
@chaliy chaliy merged commit aa9255f into main Mar 26, 2026
18 of 23 checks passed
@chaliy chaliy deleted the fix/issue-833-sort-numeric-prefix branch March 26, 2026 17:11
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.

bug: sort -n doesn't extract leading numeric prefix from strings

1 participant