File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
src/uucore/src/lib/features/i18n Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -80,9 +80,10 @@ pub fn locale_cmp(left: &[u8], right: &[u8]) -> Ordering {
8080 if get_collating_locale ( ) . 0 == DEFAULT_LOCALE {
8181 left. cmp ( right)
8282 } else {
83+ // Fall back to byte comparison if collator is not available
8384 COLLATOR
8485 . get ( )
85- . expect ( "Collator was not initialized" )
86- . compare_utf8 ( left , right)
86+ . map ( |c| c . compare_utf8 ( left , right ) )
87+ . unwrap_or_else ( || left . cmp ( right) )
8788 }
8889}
Original file line number Diff line number Diff line change @@ -2713,4 +2713,21 @@ fn test_locale_complex_utf8_sorting() {
27132713 . stdout_is ( "apple\n Apple\n banana\n Banana\n zebra\n Zebra\n " ) ;
27142714}
27152715
2716+ #[ test]
2717+ fn test_locale_utf8_with_key_field ( ) {
2718+ // Regression test for issue #10909
2719+ // Sort should not panic when using -k flag with UTF-8 locale
2720+ // The bug occurred when rayon worker threads tried to access an uninitialized collator
2721+ let input = "a b 5433 down data path1 path2 path3 path4 path5
2722+ c d 5435 down data path1 path2 path3 path4 path5
2723+ e f 5436 down data path1 path2 path3 path4 path5\n " ;
2724+
2725+ new_ucmd ! ( )
2726+ . env ( "LANG" , "en_US.utf8" )
2727+ . arg ( "-k3" )
2728+ . pipe_in ( input)
2729+ . succeeds ( )
2730+ . stdout_is ( input) ;
2731+ }
2732+
27162733/* spell-checker: enable */
You can’t perform that action at this time.
0 commit comments