diff --git a/Clover/app/src/main/java/org/floens/chan/core/manager/FilterEngine.java b/Clover/app/src/main/java/org/floens/chan/core/manager/FilterEngine.java index 6128c1ddf4..6865f52c8d 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/manager/FilterEngine.java +++ b/Clover/app/src/main/java/org/floens/chan/core/manager/FilterEngine.java @@ -187,10 +187,6 @@ public boolean matches(Filter filter, Post.Builder post) { @AnyThread public boolean matches(Filter filter, boolean matchRegex, String text, boolean forceCompile) { - if (TextUtils.isEmpty(text)) { - return false; - } - if (matchRegex) { Pattern pattern = null; if (!forceCompile) { @@ -248,14 +244,16 @@ public Pattern compile(String rawPattern) { } try { - pattern = Pattern.compile(isRegex.group(1), flags); + //Don't allow an empty regex string (would match everything) + pattern = isRegex.group(1).length() > 0 ? Pattern.compile(isRegex.group(1), flags) : null; } catch (PatternSyntaxException e) { return null; } } else if (rawPattern.length() >= 2 && rawPattern.charAt(0) == '"' && rawPattern.charAt(rawPattern.length() - 1) == '"') { // "matches an exact sentence" String text = escapeRegex(rawPattern.substring(1, rawPattern.length() - 1)); - pattern = Pattern.compile(text, Pattern.CASE_INSENSITIVE); + //Don't allow only double quotes (would match everything) + pattern = rawPattern.length() != 2 ? Pattern.compile(text, Pattern.CASE_INSENSITIVE) : null; } else { String[] words = rawPattern.split(" "); String text = ""; @@ -268,8 +266,8 @@ public Pattern compile(String rawPattern) { text += "|"; } } - - pattern = Pattern.compile(text, Pattern.CASE_INSENSITIVE); + //Don't allow only spaces (would match everything after split) + pattern = !TextUtils.isEmpty(text) ? Pattern.compile(text.toString(), Pattern.CASE_INSENSITIVE) : null; } return pattern; diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/FilterLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/FilterLayout.java index 57844ab4a4..9a782e5ade 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/layout/FilterLayout.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/FilterLayout.java @@ -67,7 +67,6 @@ public class FilterLayout extends LinearLayout implements View.OnClickListener { private TextView typeText; private TextView boardsSelector; - private boolean patternContainerErrorShowing = false; private TextView pattern; private TextView patternPreview; private TextView patternPreviewStatus; @@ -341,11 +340,7 @@ public void onClick(DialogInterface dialog, int which) { private void updateFilterValidity() { boolean valid = !TextUtils.isEmpty(filter.pattern) && filterEngine.compile(filter.pattern) != null; - - if (valid != patternContainerErrorShowing) { - patternContainerErrorShowing = valid; - pattern.setError(valid ? null : getString(R.string.filter_invalid_pattern)); - } + pattern.setError(valid ? null : getString(R.string.filter_invalid_pattern)); if (callback != null) { callback.setSaveButtonEnabled(valid); @@ -385,7 +380,7 @@ private void updateFilterType() { private void updatePatternPreview() { String text = patternPreview.getText().toString(); - boolean matches = text.length() > 0 && filterEngine.matches(filter, true, text, true); + boolean matches = filterEngine.matches(filter, true, text, true); patternPreviewStatus.setText(matches ? R.string.filter_matches : R.string.filter_no_matches); }