Page MenuHomePhabricator

Language::parseFormattedNumber inteprets decimal characters too liberally
Open, Needs TriagePublic

Description

Using a 'fr' instance of Langauge, if you run parseFormattedNumber('12,') the output you get is 12. (see example)

What is going on is that Language see the comma character, assumes it is a decimal character (French uses comma, English uses period aka the decimal "point") and therefore, consumes it and replaces it with a decimal point.

This should only happen if there is a digit after the comma. "12,3" should be interpretted as "12.3" but "12," should remain untouched.

Event Timeline

Huji renamed this task from Language:parseFormattedNumber inteprets decimal characters too liberally to Language::parseFormattedNumber inteprets decimal characters too liberally.Jul 26 2020, 1:36 AM

I'm afraid the method was supposed to convert a single number (parse formatted number), not a string with other arbitrary text (judging from the test cases). So the use in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ParserFunctions/+/614582 doesn't seem appropriate. There should probably be a method parsing the string using some regex and replacing matches using parseFormattedNumber.

@matej_suchanek you are correct that our use of this function in that patch is not appropriate. I will respond more on the related task.

Nevertheless, I still think the decimal character should only be accepted if it is followed by a digit.