Inconsistent sort behavior
While doing some sorting with new sort (v 0.8.0) that came with Ubuntu 26.04, I have noticed an inconsistent behavior. Attaching example sort1.txt and sort2.txt files that:
- lines 6&7 got randomly assigned using sort;
- stay invariant if you run over sort (again).
Expected behavior:
- files sort1.txt and sort2 are identical;
- sort produces the same output for inputs from sort1.txt or sort2.txt
I am currently looking into this, I currently worked on a minimal example, that shows that this is indeed an issue. Two files containing:
01
0_1
02
and
0_1
01
02
will produce:
01
0_1
0_1
01
02
02
Looking into the compare code, when setting the global_settings.precomputed.fast_lexicographic = true; it will produce:
01
01
02
02
0_1
0_1
Using --sort=<general-numeric,human-numeric> also produces a well sorted list.
I created a PR to fix this issue. https://github.com/uutils/coreutils/pull/12013
@sylvestre This bug is quite severe. I imagine it will need patching in Ubuntu.
The issue is all the programs with localization implemented (e.g. sort, join, expr) use AlternateHandling::Shifted. This leads to some obviously incorrect behavior, for example:
$ expr 'USA' = 'U.S.A.'
0
$ uu_expr 'USA' = 'U.S.A.'
1
$ printf '_\n.\n\n' | sort -u
.
_
$ printf '_\n.\n\n' | uu_sort -u
_
@pixelb FYI, I'll have a look at adding some tests with punctuation later.