Make TemplateRemoveer *actually* remove templates

Strangely, the \}\} regex seems to match the | character. Weird,
confusing and scary. This *might* be an ICU Regex vs Java native
Regex thing, or it might be something more subtle / obvious that
I am missing.

However since we're simply doing character matches, doing a simple
equals should suffice for this.

Goddamn wikitext.

Bug: 47380
This commit is contained in:
YuviPanda 2013-04-23 20:38:36 +05:30
parent 9288aec9d6
commit e0c23a6038

View file

@ -12,10 +12,6 @@ public class TemplateRemoveModifier extends PageModifier {
public static final String PARAM_TEMPLATE_NAME = "template"; public static final String PARAM_TEMPLATE_NAME = "template";
public static final Pattern PATTERN_TEMPLATE_OPEN = Pattern.compile("\\{\\{");
public static final Pattern PATTERN_TEMPLATE_CLOSE = Pattern.compile("\\}\\}");
public TemplateRemoveModifier(String templateName) { public TemplateRemoveModifier(String templateName) {
super(MODIFIER_NAME); super(MODIFIER_NAME);
try { try {
@ -30,6 +26,7 @@ public class TemplateRemoveModifier extends PageModifier {
this.params = data; this.params = data;
} }
// Never get into a land war in Asia.
@Override @Override
public String doModification(String pageName, String pageContents) { public String doModification(String pageName, String pageContents) {
String templateRawName = params.optString(PARAM_TEMPLATE_NAME); String templateRawName = params.optString(PARAM_TEMPLATE_NAME);
@ -47,13 +44,14 @@ public class TemplateRemoveModifier extends PageModifier {
int startIndex = matcher.start(); int startIndex = matcher.start();
int curIndex = matcher.end(); int curIndex = matcher.end();
while(curIndex < pageContents.length()) { while(curIndex < pageContents.length()) {
if(PATTERN_TEMPLATE_OPEN.matcher(pageContents).find(curIndex)) { if(pageContents.substring(curIndex, curIndex + 2).equals("{{")) {
braceCount++; braceCount++;
} else if(PATTERN_TEMPLATE_CLOSE.matcher(pageContents).find(curIndex)) { } else if(pageContents.substring(curIndex, curIndex + 2).equals("}}")) {
braceCount--; braceCount--;
} }
curIndex++; curIndex++;
if(braceCount == 0) { if(braceCount == 0) {
curIndex++; // To account for the last brace in the closing }} pair
break; break;
} }
} }