tatuylonen / wikitextprocessor

Python package for WikiMedia dump processing (Wiktionary, Wikipedia etc). Wikitext parsing, template expansion, Lua module execution. For data extraction, bulk syntax checking, error detection, and offline formatting.
Other
94 stars 23 forks source link

Detect template loop formed in Lua code #333

Closed xxyzz closed 1 week ago

xxyzz commented 1 week ago

Fix tatuylonen/wiktextract#894

test_template16 is removed because it's not a valid test, it has infinite loop.

I can't reproduce the loop in test, but it has the same repeated expand stack as the error message. The test stops at "too deep recursion" error without the change but it fixes the loop in page "今生".

kristian-clausal commented 1 week ago

I had only minor comments that I'm not sure are valid, otherwise this looks good. I'm worried how performant the loop checking is, but that's not something we can avoid easily.

xxyzz commented 1 week ago

Add mw.logObject(template:get_arguments()) at line 93 in https://en.wiktionary.org/wiki/Module:zh-translit and preview page "今生", the Lua log will show loop detected for template "m".

kristian-clausal commented 1 week ago

Do you think they know about this on the Wiktionary side of things?

xxyzz commented 1 week ago

It's not a problem on Wiktionary because the parser could stop the loop, I think maybe Lua module editors don't need to worry about it.