Page MenuHomePhabricator

mw.ustring methods don't allow numbers where corresponding string methods do
Closed, ResolvedPublic

Description

In this module:

local p = {}

function p.main(frame)
local builder = mw.html.create('span'):css('opacity', 0)
return tostring(builder)
end

return p

The call to p.main() results in the following script error:

Lua error: bad argument #1 to 'gsub' (string expected, got number).

Backtrace:

[C]: in function "v"
mw.ustring.lua:61: ?
(tail call): ?
mw.html.lua:113: in function "_build"
mw.html.lua:51: ?
[C]: in function "tostring"
Module:Sandbox/Jackmcbarn:5: in function "chunk"
mw.lua:478: ?

Version: unspecified
Severity: normal

Details

Reference
bz67201

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:30 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz67201.

Not actually a bug in mw.html, it's that mw.ustring isn't autoconverting numbers where Lua's standard string library does.

Change 142563 had a related patch set uploaded by Jackmcbarn:
Fix strange mw.html errors with numeric arguments

https://gerrit.wikimedia.org/r/142563

Well, it's partially both. There's other ways to cause this that make it fail in places other than ustring.

Change 142567 had a related patch set uploaded by Anomie:
mw.ustring functions should accept numbers where string functions do

https://gerrit.wikimedia.org/r/142567

Change 142567 merged by jenkins-bot:
mw.ustring functions should accept numbers where string functions do

https://gerrit.wikimedia.org/r/142567

Both related patches merged

Change 142563 merged by jenkins-bot:
Fix strange mw.html errors with numeric arguments

https://gerrit.wikimedia.org/r/142563