Last modified: 2014-01-13 16:48:48 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T58199, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 56199 - {{formatnum}} arguments 'R' and 'NOSEP' should match the entire string, not just part of the string
{{formatnum}} arguments 'R' and 'NOSEP' should match the entire string, not j...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
1.22.0
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-26 04:21 UTC by gnosygnu
Modified: 2014-01-13 16:48 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description gnosygnu 2013-10-26 04:21:20 UTC
[This issue was discovered by https://de.wikipedia.org/wiki/Benutzer:Schnark]

-------
Summary
-------

{{formatnum}} interprets any string **containing** the letter 'R' as a flag for 'rawsuffix'.

Hence, {{formatnum:1,234.56|any string that has the capital letter 'R'}} is equivalent to {{formatnum:1,234.56|R}}. This also applies to {{formatnum:1,234.56|Random}}, {{formatnum:1,234.56|EVERYTHING}}, etc.. In all cases, 1234.56 will be generated as the output. Instead, the function should discard the argument and output 1,234.56.

The same also applies to the 'NOSEP' argument. For example, {{formatnum:1234.56|any argument that has the string 'NOSEP'}} will output 1234.56. It should output 1,234.56.

-----------
Explanation
-----------
* In MessagesEn.php, 'rawsuffix' is defined as 'R'. Note that few languages overrides this magic word.

* CoreParserFunctions.php defines a function called formatnum which calls "self::matchAgainstMagicword( 'rawsuffix', $arg )"

* matchAgainstMagicword in turn calls the match function in MagicWord.php

* MagicWord::match does "preg_match( $this->getRegex(), $text )". For rawsuffix, this will match any string that has the letter 'R'

* The same situation arises for 'nocommafysuffix' and 'NOSEP'

--------------
Recommendation
--------------

* Change the behavior to match the **entire** string 'R', not just **any** part of it.

---------------
Possible issues
---------------

* This may break existing usage. For example, {{formatnum:1234.56|RAW}} is currently permissible, but should be invalid. This can be mitigated by adding 'RAW' as another magic word for 'rawsuffix' in MessagesEn.php
Comment 1 Umherirrender 2013-10-26 07:11:16 UTC
formatnum is part of core -> moving

There is MagicWord::matchStart which allows to reduce the side effect to a R at the begin.

Using MagicWord::matchStartAndRemove and check, if the rest is a empty string is also possible. Maybe someone knows a better way.
Comment 2 Gerrit Notification Bot 2013-12-08 10:04:40 UTC
Change 100198 had a related patch set uploaded by Umherirrender:
Raw option of parser functions should match complete word

https://gerrit.wikimedia.org/r/100198
Comment 3 Gerrit Notification Bot 2014-01-12 22:29:34 UTC
Change 100198 merged by jenkins-bot:
Raw option of parser functions should match complete word

https://gerrit.wikimedia.org/r/100198
Comment 4 Umherirrender 2014-01-13 16:48:48 UTC
successfully merged

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links