mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user