Page MenuHomePhabricator

pairs() doesn't preserve the order of parameters passed to the module
Open, Needs TriagePublic

Description

Steps to reproduce:

  1. Create a module with code
local p = {}

function p.main(frame)
	local s = ''
	for k, v in pairs(frame.args) do
		s = s .. '|' .. k .. '=' .. v
	end
	return s
end

return p
  1. Call it from any page with code
{{#invoke: Module name | main
| param1 = val
| param2 = val
| param3 = val
| param4 = val
| param5 = val
}}

You will see the parameters in random order (in my case, |param1=val|param4=val|param2=val|param5=val|param3=val). The desired behaviour for the pairs() function is to traverse keys in their real order in the template transclusion code, which will result in the corresponding output.

Preserving the order of parameters would be extermely useful:

  1. for templates that demonstrate the transclusion code and, in some cases, the rendering of other templates ({{tlc}}, {{xpd}} in enwiki). It would eliminate the need to use substitutes like {{=}} or | in them;
  2. for modules (example in ruwiki) that fix incorrect uses of = in template parameters which is processed as a parameter & value pair instead of a whole value which is desired (for example, {{template|http://www.example.com?a=b}} breaks because of =).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 16 2018, 3:06 PM
Nirmos added a subscriber: Nirmos.Jun 24 2018, 5:41 PM
Vvjjkkii renamed this task from pairs() doesn't preserve the order of parameters passed to the module to rsaaaaaaaa.Jul 1 2018, 1:03 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from rsaaaaaaaa to pairs() doesn't preserve the order of parameters passed to the module.Jul 2 2018, 4:51 AM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.