#89 Page.RemoveFromCategory does not handle spaces well

closed-fixed
nobody
None
2012-06-03
2012-04-29
justin
No

The method Page.RemoveFromCategory does not handle categories that contain spaces after the colon but before the category name (e.g [[Category: Category Name]]). I've made the following fixes to properly handle this case:

In RemoveFromCategory, I've added "+ @"\s?" +" to the Replace command for the Category regex, to find any type of line break or space/tab that may be inserted, and to find only 0 or 1 of these. This could be tightened up to find only a single or more space too, which would be safer.

text = Regex.Replace(text, @"\[\[((?i)" + site.namespaces["14"] + "|" +
Site.wikiNSpaces["14"] + "):" + @"\s?" + regexCategoryName + @"(\|.*?)?]]\r?\n?", ""); //*JSG - Add space to regex

In GetCategories, I've added a Trim() call to remove spaces from the names of categories as they are found:
matchStrings[i] = matches[i].Groups[4].Value.Trim(); //*JSG - Strip off spaces in Category name

Please let me know if you have any questions at all!
Thanks,
Justin

Discussion

  • CodeDriller
    CodeDriller
    2012-04-29

    • status: open --> open-accepted
     
  • CodeDriller
    CodeDriller
    2012-04-29

    Ok.

     
  • CodeDriller
    CodeDriller
    2012-06-03

    • status: open-accepted --> closed-fixed
     
  • CodeDriller
    CodeDriller
    2012-06-03

    Fixed in version 2.101.