Page MenuHomePhabricator

#expr outputs negatives with hyphen-minus U+002D [-] instead of minus sign U+2212 [−], inconsistent with formatnum
Closed, DeclinedPublicBUG REPORT

Description

Note the following:

This is with parser functions (refer to https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions for background info):

  • {{formatnum:-8}} and {{formatnum:−8}} both output −8 (using minus sign − U+2212).
  • {{#expr 1-9}} and {{#expr 1−9}} both output -8 (using hyphen-minus symbol - U+002D)

This is inconsistent.

Note that {{formatnum}} was set up like this after considerations at T10327: Language::formatNum() should prefix negative values with − (minus sign U+2212).

What should have happened instead?:

#expr should also output negative numbers using minus sign, for consistency with T10327: Language::formatNum() should prefix negative values with − (minus sign U+2212).

#expr and formatnum do both interpret − as a minus sign, so if they are somehow nested, this shouldn't break anything.

Notes

File to be changed:
https://gerrit.wikimedia.org/g/mediawiki/extensions/ParserFunctions/+/master/includes/ExprParser.php

The patch that fixed T10327: Language::formatNum() should prefix negative values with − (minus sign U+2212) by @cscott is at https://gerrit.wikimedia.org/r/c/mediawiki/core/+/635546/14

Suggests we need to add:

			# T405240: Make formatted numbers prettier by using a
			# proper Unicode 'minus' character.
			$number = strtr( $number, [ '-' => "\u{2212}" ] );

AND also update unit tests to check this is all working properly. These are located in tests/phpunit/unit/ExpressionTest.php:
(URL https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/ParserFunctions/+/master/tests/phpunit/unit/ExpressionTest.php)

Event Timeline

This is the correct behavior. {{#expr:}} does not perform pretty number formatting, only {{formatnum:}} does.

For a more obvious example, compare {{#expr:-123456.789}} and {{formatnum:-123456.789}} at https://fa.wikipedia.beta.wmcloud.org/. The first outputs -123456.789, and the second outputs −۱۲۳٬۴۵۶٫۷۸۹.

Pppery awarded a token.

I'm not totally convinced by this argument.

A practical argument is that if you changed it that way, then you'd break Scribunto modules that pass the result of {{#expr:}} to the Lua tonumber function.