sort: fix locale collation strength for hyphen ordering (#12677)

Set Strength::Quaternary on the ICU collator so that punctuation like
hyphens sort before alphanumerics in UTF-8 locales, matching GNU sort
behavior.

Fixes #12542
This commit is contained in:
Juan Cruz Mateos
2026-06-07 16:55:03 -03:00
committed by GitHub
parent 5fd68db078
commit 80cc829771
2 changed files with 20 additions and 0 deletions
@@ -70,6 +70,7 @@ 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);
opts.strength = Some(Strength::Quaternary);
try_init_collator(opts)
}
+19
View File
@@ -3017,4 +3017,23 @@ fn test_consistent_sorting_with_i18n_collate() {
.stdout_is(expected_output);
}
#[test]
fn test_sort_locale_punctuation_weights() {
// Test for issue #12542
let input = "file10\nfile-10\n";
let expected_output = "file-10\nfile10\n";
new_ucmd!()
.env("LC_ALL", "en_US.UTF-8")
.pipe_in(input)
.succeeds()
.stdout_is(expected_output);
new_ucmd!()
.env("LC_ALL", "C")
.pipe_in(input)
.succeeds()
.stdout_is(expected_output);
}
/* spell-checker: enable */