Page MenuHomePhabricator

KeyNotFoundException when assigning namespace aliases
Open, Needs TriagePublic

Description

I’m using the latest version of AWB (5.8.8.1) on a custom wiki which unfortunately has problematic namespace settings. The following code in SiteInfo throws a KeyNotFoundException:

namespaceAliases = Variables.PrepareAliases(namespaces);

foreach (XmlNode xn in query["namespacealiases"].GetElementsByTagName("ns"))
{
    int id = int.Parse(xn.Attributes["id"].Value);

    if (id != 0) namespaceAliases[id].Add(xn.InnerText);
}

This is because there is a namespace alias from namespace id 104 to Type but there is no namespace 104 defined. So PrepareAliases will never set up the key in the namespaceAliases dictionary, and as such accessing the aliases list with namespaceAliases[id] will fail.

A simple fix would be to add an explicit key check before adding the alias, e.g.:

if (!namespaceAliases.ContainsKey(id))
    namespaceAliases[id] = new List<string>();

If desired, I can provide a patch for this (AWB being on SVN makes this kind of a PITA though ;P).

Event Timeline

poke created this task.Dec 5 2016, 9:09 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 5 2016, 9:09 PM