Page MenuHomePhabricator

mw.title.new('#') returns object that errors when expensive data is accessed
Open, Needs TriagePublic

Description

When I do mw.title.new('#'), Lua is broken, see:

=mw.title.new('#')==nil
false
=mw.title.new('#').exists
Lua error in mw.title.lua at line 206: bad argument #1 to 'pairs' (table expected, got nil).

Backtrace:

[C]: in function "pairs"
mw.title.lua:206: ?
console input:11: ?
[C]: ?

Perhaps it should work similarly to when I pass just an empty string?

=mw.title.new('')==nil
true

Event Timeline

Urbanecm created this task.Dec 13 2019, 2:27 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 13 2019, 2:27 PM
DannyS712 renamed this task from mw.title.new('#') returns a wierd object to mw.title.new('#') returns a weird object.Sep 27 2020, 1:32 PM
DannyS712 updated the task description. (Show Details)
Ammarpad added a subscriber: Ammarpad.EditedSep 28 2020, 6:12 AM

This needs to be fixed in includes/engines/LuaCommon/TitleLibrary.php if someone is interested. In PHP side, standalone '#' string will construct a valid title object with title text morphed to empty string (because of stripping of illegal chars) which will cause it to eventually just redirects to whatever the mainpage is.

Ammarpad renamed this task from mw.title.new('#') returns a weird object to mw.title.new('#') does not return anything but error.Sep 30 2020, 7:25 PM
Erutuon renamed this task from mw.title.new('#') does not return anything but error to mw.title.new('#') returns object that errors when expensive data is accessed.Sep 30 2020, 8:05 PM
Erutuon added a comment.EditedSep 30 2020, 8:14 PM

Note on my change to the title: mw.title.new("#") returns an object, but accessing any of the expensive fields causes an error to be thrown in mw.title.lua. When I type the following lines one-by-one into the console, the field accesses on the title object all throw the same error:

title = mw.title.new("#")
= title.exists
= title.id
= title.isRedirect
= title.contentModel

This can be fixed in mw.title.lua by checking that php.getExpensiveData( t.fullText ) on line 209 is not nil before iterating over it with pairs.

mw.title.new("#")

It does not return an object, there is no object to return

This can be fixed in mw.title.lua by checking that php.getExpensiveData( t.fullText ) on line 209 is not nil before iterating over it with pairs.

That's not the root cause of the problem, it merely propagates to there, and so that's no right place to tackle the issue

mw.title.new("#")

It does not return an object, there is no object to return

I don't understand. By an object I mean a Lua table, and mw.title.new("#") is certainly a table at the moment because this assertion succeeds:

assert(type(mw.title.new("#")) == "table")

This can be fixed in mw.title.lua by checking that php.getExpensiveData( t.fullText ) on line 209 is not nil before iterating over it with pairs.

That's not the root cause of the problem, it merely propagates to there, and so that's no right place to tackle the issue

Right, I guess it would be a bandaid. Ideally mw.title.new("#") should return nil rather than a table, as the documentation says it does. I'm not familiar enough with PHP or the MediaWiki codebase to fix this myself.

I think I fixed this... at sometime

There are two ways to fix it, either to return null or to behave as PH/JS do, i.e return a Title object that will eventually redirects to main page, I think that's better.