formatnum breaks strip markers and wikilinks
Closed, ResolvedPublic

Description

This stems from a discussion at [[en:WP:VPT#Strange categories due to .7B.7Bfact.7D.7D tags]].

It seems from the code comments that the formatnum parser function is only supposed to apply to numeric input, but as written it will happily reformat any number anywhere in the text input. This easily mangles strip markers (see the URL above), and also causes issues if someone winds up with a wikilink in the formatnum input (e.g. "Category:Foo in 2009" becomes "Category:Foo in 2,009", possibly from something like "1234{{fact|date=April 2008}}" being passed into a template parameter that is formatnummed).

Possible fixes off the top of my head:

  1. formatnum could insist on its input being numeric, and either return the input unchanged or return an error if not.
  2. formatnum could pull off the leading numeric text, and return anything after the first non-numeric unaltered. E.g. "1234 foo bar 5678" => "1,234 foo bar 5678".
  3. The documentation and comments could be updated to define this as the expected behavior.

In either the first or third cases, a workaround for the enwiki templates would be to supply both a numeric and a postscript parameter (e.g. instead of "{{infobox|pop=1234{{fact}}}}", it could be "{{infobox|pop=1234|pop ref={{fact}}}}").


Version: 1.16.x
Severity: enhancement
URL: http://en.wikipedia.org/w/api.php?action=expandtemplates&title=foo&text={{formatnum:%3Cnowiki/%3E}}&format=yamlfm

bzimport set Reference to bz21054.
Anomie created this task.Via LegacyOct 8 2009, 1:00 PM
brion added a comment.Via ConduitOct 8 2009, 5:01 PM

Scary parser internals... assigning to Tim. :)

Nikerabbit added a comment.Via ConduitOct 8 2009, 5:07 PM

I would go for at least 3., and 1. if possible.

bzimport added a comment.Via ConduitOct 19 2009, 3:06 PM

paul.copperman wrote:

*** Bug 21178 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitMar 9 2010, 7:10 PM

ayg wrote:

I'd think (1) or (2) would break things, no? Probably users are depending someplace on $1234.56 becoming $1,234.56, or who knows what.

tstarling added a comment.Via ConduitMar 20 2012, 4:42 AM

I fixed the strip tag breakage in r114231. I don't think formatnum should skip links, so I'm marking the bug fixed on the basis that what can be done here has been done.

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.