diff --git a/CHANGELOG.md b/CHANGELOG.md index b2fb977..e118995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ Unreleased ### Fixed +- Recognize locale thousands separators when `COMPATIBILITYNORMALIZE` is enabled, + including non-breaking spaces used by French locales. - CLI no longer strips leading and trailing whitespace from entries, which could change the sort order ([@baldassarreFe](https://github.com/baldassarreFe), issue diff --git a/natsort/utils.py b/natsort/utils.py index 01996dd..012a03a 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -644,8 +644,10 @@ def input_string_transform_factory(alg: NSType) -> StrToStr: nodecimal += r"(? None: assert natsorted(given) == expected +@pytest.mark.parametrize("separator", ["\u00a0", "\u202f"]) +@pytest.mark.parametrize("normalize", [ns.DEFAULT, ns.COMPATIBILITYNORMALIZE]) +@pytest.mark.parametrize("number_type", [ns.INT, ns.FLOAT]) +def test_natsorted_normalizes_locale_thousands_separator( + separator: str, + normalize: NSType, + number_type: NSType, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr("natsort.utils.get_thousands_sep", lambda: separator) + monkeypatch.setattr("natsort.utils.get_decimal_point", lambda: ",") + if number_type == ns.FLOAT: + expected = ["999,9", f"1{separator}000,05", f"1{separator}000,5"] + else: + expected = ["999", f"1{separator}000", f"1{separator}001"] + + assert ( + natsorted(reversed(expected), alg=ns.LOCALENUM | normalize | number_type) + == expected + ) + + def test_natsorted_can_sort_as_signed_floats_with_exponents( float_list: list[str], ) -> None: