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.Value.Trim(); //*JSG - Strip off spaces in Category name
Please let me know if you have any questions at all!
Log in to post a comment.