]> git.ipfire.org Git - thirdparty/babel.git/commit
Allow alternative space characters as group separator when parsing numbers (#1007)
authorRonan Amicel <ronan@amicel.net>
Mon, 22 Apr 2024 06:53:54 +0000 (08:53 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Apr 2024 06:53:54 +0000 (09:53 +0300)
commitc0fb56e6a5a7fa9268b5164db0ff0fc28524d648
treec12fd062c97be495eba408f928bd2633d74f2665
parentfe82fbc90d8044d17bfc4ae1c7a0cb24e85153ef
Allow alternative space characters as group separator when parsing numbers (#1007)

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in https://github.com/python-babel/babel/issues/637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow certain other space characters when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
babel/numbers.py
tests/test_numbers.py