Page MenuHomePhabricator

getCategoryLinks should catch invalid category title exceptions
Closed, ResolvedPublic

Description

Today I noticed that when category.py tries to move this template from one category to another, it failed with a nasty InvalidTitle error message. My investigations showed it occurs because the template's Doc page currently contains this wikicode:

[[رده:فیلم‌های زبان {{#invoke:string|replace|{{{زبان}}}|%[%[([^%[%]]*) [%(]?زبان[%)]?{{!}}[^%[%]]*%]%]|%1|plain=false}}]]

To make it easier to understand for our LTR-language speaking developers, that is akin to:

[[Category:movies in {{#invoke:string|replace|{{{language}}}|%[%[([^%[%]]*) [%(]?language[%)]?{{!}}[^%[%]]*%]%]|%1|plain=false}}]]

Where the output would be something like [[Category:movies in English]]. But this confuses textlib.getCategoryLinks when it tries to check for a category with that name (basically, it looks for a category whose name starts with Category:movies in {{ and { is an invalid character in page titles, hence an InvalidTitle error is resulted).

The real issue is that getCategoryLinks() does not use try .. except when trying to fetch the categories. So anytime a [[Category:...]] link is created on-the-fly (using templates or modules), an invalid title (i.e. one that contains {) will pass through causing an exception and failing the entire code.

Event Timeline

Huji renamed this task from getCategoryLinks should not fail when an invalid category title is extracted to getCategoryLinks should catch invalid category title exceptions.Dec 30 2016, 4:23 AM

Change 329656 had a related patch set uploaded (by Huji):
getCategoryLinks should catch invalid category title exceptions

https://gerrit.wikimedia.org/r/329656

Huji triaged this task as Medium priority.Dec 30 2016, 4:27 AM

Change 329656 merged by jenkins-bot:
getCategoryLinks should catch invalid category title exceptions

https://gerrit.wikimedia.org/r/329656

Huji removed a project: Patch-For-Review.