python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 433 forks source link

Allow alternative space characters as group separator when parsing numbers #1007

Closed ronnix closed 2 months ago

ronnix commented 1 year ago

Context

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.

Contents

This PR goes further by changing both parse_number and parse_decimal to allow any other space character (using the \s character class of regular expressions) any of those 3 space characters when the expected group symbol is itself one such space character, but is not present in the string to parse.

Unit tests are included.

akx commented 2 months ago

@ronnix Sorry for dropping the ball on my part here... Could you rebase this? :)

ronnix commented 2 months ago

@akx done!

ronnix commented 2 months ago

@akx I fixed the linter error

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.69%. Comparing base (e0d1018) to head (181d701). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1007 +/- ## ========================================== - Coverage 90.99% 90.69% -0.31% ========================================== Files 26 26 Lines 4444 4449 +5 ========================================== - Hits 4044 4035 -9 - Misses 400 414 +14 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.