0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

Add a excludeRegex field for Pattern Checker

This commit is contained in:
blankie 2023-03-23 18:49:33 +07:00
parent f47c63c342
commit f31be1033e
No known key found for this signature in database
GPG Key ID: CC15FC822C7F61F5
3 changed files with 22 additions and 6 deletions

View File

@ -59,7 +59,13 @@ public class PatternCatalog extends JsonCatalog {
)
.put("enabled", "false")
)
.put("Fandom ➔ BreezeWiki", new JSONObject()
.put("regex", "^https?://([a-z0-9-]+)\\.fandom\\.com/(.*)")
.put("excludeRegex", "^https?://www\\.fandom\\.com/")
.put("replacement", "https://breezewiki.com/$1/$2")
.put("enabled", "false")
)
;
}
}
}

View File

@ -23,6 +23,7 @@ import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;
/**
* This module checks for patterns characters in the url
@ -119,12 +120,20 @@ class PatternDialog extends AModuleDialog {
if (data == null) continue;
if (!data.optBoolean("enabled", true)) continue;
String regex = data.optString("regex", null);
String excludeRegex = data.optString("excludeRegex", null);
// properly formed?
if (regex == null) continue;
// applied?
message.applied = urlData.getData(APPLIED + pattern) != null;
// check regexp
String regex = data.optString("regex", "(?!)");
if (url.matches(".*" + regex + ".*")) {
// check pattern
boolean matches = Pattern.compile(regex).matcher(url).find();
if (matches && excludeRegex != null) {
matches = !Pattern.compile(excludeRegex).matcher(url).find();
}
if (matches) {
message.matches = true;
// check replacements
String replacement = null;

View File

@ -127,7 +127,8 @@ Built-in patterns include:
<string name="mPttrn_noSchemeHttps">Missing HTTPS scheme.</string>
<string name="mPttrn_ok">No matching patterns</string>
<string name="mPttrn_editor">"Here you can edit or add new pattern. Format:
- 'regex': string: valid java regex that will be matched against the url.
- 'regex': string: a valid java regex that must match for the entire pattern to match.
- 'excludeRegex': string: if provided, a valid java regex that must not match for the entire pattern to match.
- 'replacement': string|list: if provided, the 'fix' button will run 'url=url.replaceAll(regex,replacement)'. If list, replacement will be a random element from it.
- 'automatic': boolean: set to true to automatically apply the pattern.
- 'enabled': boolean: set to false to disable the pattern.
@ -306,4 +307,4 @@ In the field below you can put flags that will overwrite the default ones, those
While using the module you can hold the edit button to set the flags to the default flags. You can add flags by writing their name in the flags field"</string>
<string name="mFlag_flagHint">Flag name</string>
</resources>
</resources>