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 added a subscriber: JackPotte.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 13 2015, 10:34 PM
Anomie closed this task as Invalid.Jul 13 2015, 11:53 PM
Anomie claimed this task.
Anomie added a subscriber: Anomie.

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).

Jackmcbarn added a subscriber: Jackmcbarn.EditedJul 14 2015, 4:18 PM

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.

Jackmcbarn set Security to None.
Restricted Application added a subscriber: StudiesWorld. · View Herald TranscriptDec 4 2015, 3:21 AM