Page MenuHomePhabricator

callParserFunction argument handling should match wikitext
Closed, ResolvedPublic

Description

The GeoData extension provides a parser function called "#coordinates". When the lua function callParserFunction is used in a module to call #coordinates with two integer arguments, a fatal exception occurs.

Steps to reproduce:

  1. Create "Module:Sandbox" with this content:

local sandbox = {};
function sandbox.test(frame)

frame:callParserFunction('#coordinates', {80, 30})
return "abc"

end
return sandbox

  1. Create a page with "{{#invoke:Sandbox|test}}" and save.

(example on frwiki: https://fr.wikipedia.org/w/index.php?title=Module:Sandbox&oldid=102691262, https://fr.wikipedia.org/wiki/Utilisateur:Orlodrim/callParserFunction)

I am not completely sure that it is a bug in Scribunto, rather than in GeoData, but note that the following code (with string arguments) does not cause an exception:

frame:callParserFunction('#coordinates', {'80', '30'})

Stack trace on my personal test wiki:

[a6b06752] /mediawiki-git/core/index.php?title=User:127.0.0.1&action=submit Exception from line 1205 of /home/orlodrim/mediawiki/core/includes/parser/Preprocessor_DOM.php: PPFrame_DOM::expand: Invalid parameter type

Backtrace:

#0 /home/orlodrim/mediawiki/extensions/GeoData/CoordinatesParserFunction.php(82): PPFrame_DOM->expand(integer)
#1 /home/orlodrim/mediawiki/extensions/GeoData/CoordinatesParserFunction.php(49): CoordinatesParserFunction->parseArgs(PPTemplateFrame_DOM, array)
#2 [internal function]: CoordinatesParserFunction->coordinates(Parser, PPTemplateFrame_DOM, array)
#3 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(3616): call_user_func_array(array, array)
#4 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(502): Parser->callParserFunction(PPTemplateFrame_DOM, string, array)
#5 [internal function]: Scribunto_LuaEngine->callParserFunction(string, string, array)
#6 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(401): call_user_func_array(array, array)
#7 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(379): Scribunto_LuaStandaloneInterpreter->callback(string, array)
#8 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(426): Scribunto_LuaStandaloneInterpreter->handleCall(array)
#9 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaStandalone/LuaStandaloneEngine.php(307): Scribunto_LuaStandaloneInterpreter->dispatch(array)
#10 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(195): Scribunto_LuaStandaloneInterpreter->callFunction(Scribunto_LuaStandaloneInterpreterFunction, Scribunto_LuaStandaloneInterpreterFunction)
#11 /home/orlodrim/mediawiki/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(672): Scribunto_LuaEngine->executeFunctionChunk(Scribunto_LuaStandaloneInterpreterFunction, PPTemplateFrame_DOM)
#12 /home/orlodrim/mediawiki/extensions/Scribunto/common/Hooks.php(108): Scribunto_LuaModule->invoke(string, PPTemplateFrame_DOM)
#13 [internal function]: ScribuntoHooks::invokeHook(Parser, PPFrame_DOM, array)
#14 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(3616): call_user_func_array(string, array)
#15 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(3333): Parser->callParserFunction(PPFrame_DOM, string, array)
#16 /home/orlodrim/mediawiki/core/includes/parser/Preprocessor_DOM.php(1113): Parser->braceSubstitution(array, PPFrame_DOM)
#17 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(3150): PPFrame_DOM->expand(PPNode_DOM, integer)
#18 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(1212): Parser->replaceVariables(string)
#19 /home/orlodrim/mediawiki/core/includes/parser/Parser.php(395): Parser->internalParse(string)
#20 /home/orlodrim/mediawiki/core/includes/content/WikitextContent.php(306): Parser->parse(string, Title, ParserOptions, boolean, boolean, NULL)
#21 /home/orlodrim/mediawiki/core/includes/EditPage.php(3248): WikitextContent->getParserOutput(Title, NULL, ParserOptions)
#22 /home/orlodrim/mediawiki/core/includes/EditPage.php(2185): EditPage->getPreviewText()
#23 /home/orlodrim/mediawiki/core/includes/EditPage.php(441): EditPage->showEditForm()
#24 /home/orlodrim/mediawiki/core/includes/actions/EditAction.php(50): EditPage->edit()
#25 /home/orlodrim/mediawiki/core/includes/actions/EditAction.php(74): EditAction->show()
#26 /home/orlodrim/mediawiki/core/includes/Wiki.php(441): SubmitAction->show()
#27 /home/orlodrim/mediawiki/core/includes/Wiki.php(305): MediaWiki->performAction(Article, Title)
#28 /home/orlodrim/mediawiki/core/includes/Wiki.php(596): MediaWiki->performRequest()
#29 /home/orlodrim/mediawiki/core/includes/Wiki.php(460): MediaWiki->main()
#30 /home/orlodrim/mediawiki/core/index.php(49): MediaWiki->run()
#31 {main}


Version: unspecified
Severity: major

Details

Reference
bz63597

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:18 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz63597.
bzimport added a subscriber: Unknown Object (MLST).

Change 124346 had a related patch set uploaded by Anomie:
Stringify numbers in frame:callParserFunction

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

Thanks Anomie for working on this bug!

I was just told by Zolo, who first ran into this problem, that a MediaWiki exception also occurs when #coordinates is called with no parameter at all (something that can never happen in wikicode, I think). Example:

frame:callParserFunction('#coordinates', {})

Is that something that you can address at the same time, or should I fill a separate bug report?

(In reply to orlodrim from comment #2)

Is that something that you can address at the same time, or should I fill a
separate bug report?

Let's retitle the bug so it covers both.

Change 124346 merged by jenkins-bot:
Improve frame:callParserFunction argument validation

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

Change should be deployed to WMF wikis with 1.24wmf5, see https://www.mediawiki.org/wiki/MediaWiki_1.24/Roadmap for the schedule.