← Back to Pull requests

uucore: ignore symbols like + | ~ at the first level of locale collation #16237

Open
jayhemnani9910 opened this pull request with 64 lines diff across 5 files
View on GitHub
jayhemnani9910 jayhemnani9910 commented on Nov 07, 2026 05:30 UTC
Author

In a UTF-8 locale, GNU sort and ls ignore symbols such as + < = > ^ | ~ at the first level, the same way they ignore punctuation. Ours only treats punctuation as variable, so these lines sort ahead of letters and digits:

$ printf '+5\n10\n' | LC_ALL=en_US.UTF-8 sort
+5
10
$ printf '+5\n10\n' | LC_ALL=en_US.UTF-8 gnusort
10
+5
$ touch a.txt b.txt '~draft' '+notes' '|pipe'; LC_ALL=en_US.UTF-8 ls     # main
+notes  |pipe  ~draft  a.txt  b.txt
$ LC_ALL=en_US.UTF-8 gnuls
a.txt  b.txt  ~draft  +notes  |pipe

The collator already uses AlternateHandling::Shifted. This sets max_variable to MaxVariable::Symbol too, so symbols are shifted like punctuation and spaces. Currency symbols stay non-variable, which already matches GNU ($5 still sorts before 10 in both). The change is in init_locale_collation, so it applies to sort, ls and test. comm, join and expr set up their own collator and are not changed.

Testing (en_US.UTF-8, GNU coreutils 9.7 as reference):

  • New test_sort_locale_symbols: fails on main, passes with the change.

  • cargo test --features "sort ls test" -- test_sort:: test_ls:: test_test::: 549 passed.

  • Each of + < = > ^ | ~ before a digit: same order as gnusort now. The existing punctuation cases (file-10, E-U/E.U/EU) are unchanged.

  • Not part of this: ties under -n, -f and other modes are still broken by bytes, which #13319 / #16090 cover.
  • Diff: 64 lines (+49 / -15) across 5 files Reviewer: sylvestre Review duration: 33970m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.34) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 64 lines diff across 5 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 4 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.250
    Real PR Conversation Timeline
    9 items
    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 07, 2026 05:30 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    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.

    sylvestre sylvestre commented on code on Nov 07, 2026 14:19 UTC
    Code Review
    src/uucore/src/lib/features/i18n/collator.rs:1
    @@ -71,6 +71,9 @@ pub fn init_locale_collation() -> bool {
         // UTF-8 locale - initialize collator with Shifted mode to match GNU behavior
         let mut opts = CollatorOptions::default();
         opts.alternate_handling = Some(AlternateHandling::Shifted);
    +    // Like glibc, also ignore symbols such as `+`, `|` and `~` at the first level, not
    +    // only spaces and punctuation
    +    opts.max_variable = Some(MaxVariable::Symbol);

    comm and join check the input order with their own collator (no max_variable), so sort | comm will now say "not in sorted order" for lines like +5.
    could you please make comm/join (and expr) use the same options, ideally through init_locale_collation?

    sylvestre sylvestre commented on code on Nov 07, 2026 14:19 UTC
    Code Review
    tests/by-util/test_sort.rs:1
    @@ -3938,6 +3938,18 @@ fn test_merge_locale_collation() {
         }
     }
     
    +#[test]
    +fn test_sort_locale_symbols() {

    please also add a test where comm or join reads this sort output without complaining

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 07, 2026 19:18 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    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.

    jayhemnani9910 jayhemnani9910 commented on Nov 07, 2026 19:25 UTC
    Author

    Thanks. comm, join and expr now take their collator options from the same function as sort, locale_collator_options() in collator.rs, and each keeps its own init as before (a0526f1). With the quaternary strength sort already uses, comm and join no longer treat lines that differ only in punctuation, like a-b and ab, as equal.

    Added test_sort_locale_symbols_comm_check_order: sort's output for +5 and 10 goes to comm --check-order, which accepts it.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 09, 2026 08:55 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    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.

    codspeed[bot] codspeed[bot] commented on Nov 09, 2026 09:31 UTC
    Bot

    <!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

    Merging this PR will degrade performance by 65.92%

    <details>
    <summary><b>1 warning, 1 note</b></summary>

    :warning: 125 benchmarks are dominated by system calls

    > System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

    > Learn more about system calls

    > See affected benchmarks

    :information_source: 1 benchmark has no flamegraph

    > The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

    > See affected benchmarks

    </details>

    ❌ 3 regressed benchmarks
    ✅ 412 untouched benchmarks
    ⏩ 70 skipped benchmarks[^skipped]

    [!WARNING]

    Please fix the performance issues or acknowledge them on CodSpeed.

    Performance Changes

    | | Mode | Benchmark | BASE | HEAD | Efficiency |
    | --- | ---- | --------- | ------ | ------ | ---------- |
    | ❌ | Memory | [` socket_addrs_direct[100000] ](https://app.codspeed.io/uutils/coreutils/branches/jayhemnani9910%3Asort-collate-symbols?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Asocket_addrs_direct%255B100000%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 8.6 KB | 68 KB | -87.29% |
    | ❌ | Memory |
    timeout_enforced | 88.8 KB | 179.6 KB | -50.56% |
    | ❌ | Memory | [
    hostname_ip_lookup[100000] ](https://app.codspeed.io/uutils/coreutils/branches/jayhemnani9910%3Asort-collate-symbols?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Ahostname_ip_lookup%255B100000%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 100.9 KB | 160.2 KB | -37.06% |

    [!TIP]

    Investigate this regression by commenting @codspeedbot fix this regression` on this PR, or directly use the CodSpeed MCP with your agent.

    ---

    <sub>Comparing <code>jayhemnani9910:sort-collate-symbols</code> (1e9dfae) with <code>main</code> (887b9e6)[^unexpected-base]</sub>

    <a href="https://app.codspeed.io/uutils/coreutils/branches/jayhemnani9910%3Asort-collate-symbols?utm_source=github&utm_medium=comment-v2&utm_content=button">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
    <img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
    </picture>
    </a>

    [^skipped]: 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
    [^unexpected-base]: No successful run was found on <code>main</code> (9137846) during the generation of this report, so 887b9e6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 28, 2026 11:27 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    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.

    Reviewers
    Assignees
    jayhemnani9910 jayhemnani9910
    Labels
    risk: low confidence: 87.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.8% (LOW) · Higher = larger blast radius
    33.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.1% · Lower = rushed or shallow review
    87.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.4% · Safe to merge
    4.4%