mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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:
parent
9288aec9d6
commit
e0c23a6038
1 changed files with 4 additions and 6 deletions
|
|
@ -12,10 +12,6 @@ public class TemplateRemoveModifier extends PageModifier {
|
|||
|
||||
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) {
|
||||
super(MODIFIER_NAME);
|
||||
try {
|
||||
|
|
@ -30,6 +26,7 @@ public class TemplateRemoveModifier extends PageModifier {
|
|||
this.params = data;
|
||||
}
|
||||
|
||||
// Never get into a land war in Asia.
|
||||
@Override
|
||||
public String doModification(String pageName, String pageContents) {
|
||||
String templateRawName = params.optString(PARAM_TEMPLATE_NAME);
|
||||
|
|
@ -47,13 +44,14 @@ public class TemplateRemoveModifier extends PageModifier {
|
|||
int startIndex = matcher.start();
|
||||
int curIndex = matcher.end();
|
||||
while(curIndex < pageContents.length()) {
|
||||
if(PATTERN_TEMPLATE_OPEN.matcher(pageContents).find(curIndex)) {
|
||||
if(pageContents.substring(curIndex, curIndex + 2).equals("{{")) {
|
||||
braceCount++;
|
||||
} else if(PATTERN_TEMPLATE_CLOSE.matcher(pageContents).find(curIndex)) {
|
||||
} else if(pageContents.substring(curIndex, curIndex + 2).equals("}}")) {
|
||||
braceCount--;
|
||||
}
|
||||
curIndex++;
|
||||
if(braceCount == 0) {
|
||||
curIndex++; // To account for the last brace in the closing }} pair
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue