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:
parent
f47c63c342
commit
f31be1033e
@ -59,6 +59,12 @@ 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")
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user