Page MenuHomePhabricator

Lua is eating the number 2 when ending mw.text.trim(mw.ustring.gsub())
Closed, InvalidPublic

Description

This page: https://fr.wikibooks.org/wiki/S%27initier_au_boulier_en_10_le%C3%A7ons/Version_imprimable comes from https://fr.wikibooks.org/wiki/Module:Version_imprimable
Today, I've noticed that "Leçon 2" was not included, because it was treated as "Leçon"

That's how I've observed a difference of treatment of the number "2" by the Lua. Actually it's removed as if it was a part of the return code (which is also 2) instead of the result:

mw.log( mw.text.trim(mw.ustring.gsub("* [[S'initier au boulier en 10 leçons/Leçon 1|Bases et vocabulaire]]", "[ \*\#\[<small>]*([^\|]*).*", "%1")))
S'initier au boulier en 10 leçons/Leçon 1

mw.log( mw.text.trim(mw.ustring.gsub("* [[S'initier au boulier en 10 leçons/Leçon 2|Bases et vocabulaire]]", "[ \*\#\[<small>]*([^\|]*).*", "%1")))
S'initier au boulier en 10 leçons/Leçon

mw.log( mw.text.trim(mw.ustring.gsub("* [[S'initier au boulier en 10 leçons/Leçon 3|Bases et vocabulaire]]", "[ \*\#\[<small>]*([^\|]*).*", "%1")))
S'initier au boulier en 10 leçons/Leçon 3

Event Timeline

JackPotte raised the priority of this task from to Needs Triage.
JackPotte updated the task description. (Show Details)
JackPotte subscribed.
Anomie claimed this task.
Anomie subscribed.

mw.ustring.gsub returns two values: the string, and the total number of matches. In this case, "S'initier au boulier en 10 leçons/Leçon 2" and 2.

Calling mw.text.trim( "S'initier au boulier en 10 leçons/Leçon 2", 2 ), of course, trims the number 2 from the string.

If this is a normal code injection it stays surprising to get a second parameter into mw.text.trim(parameter1).

gsub returns 2 values and trim takes 2 parameters. It would be surprising if it threw the second one away for no good reason.

If this is a normal code injection it stays surprising to get a second parameter into mw.text.trim(parameter1).

See http://www.lua.org/manual/5.1/manual.html#2.5.