mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-27 20:33:57 +01:00
Handle invalid regex pattern in post filter.
This commit is contained in:
parent
15b979d3ba
commit
785bb205f6
@ -35,6 +35,8 @@ import com.r0adkll.slidr.Slidr;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
@ -540,20 +542,28 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.action_save_customize_post_filter_activity) {
|
} else if (item.getItemId() == R.id.action_save_customize_post_filter_activity) {
|
||||||
constructPostFilter();
|
try {
|
||||||
Intent returnIntent = new Intent();
|
constructPostFilter();
|
||||||
returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter);
|
Intent returnIntent = new Intent();
|
||||||
setResult(Activity.RESULT_OK, returnIntent);
|
returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter);
|
||||||
finish();
|
setResult(Activity.RESULT_OK, returnIntent);
|
||||||
|
finish();
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.action_save_to_database_customize_post_filter_activity) {
|
} else if (item.getItemId() == R.id.action_save_to_database_customize_post_filter_activity) {
|
||||||
constructPostFilter();
|
try {
|
||||||
|
constructPostFilter();
|
||||||
|
|
||||||
if (!postFilter.name.equals("")) {
|
if (!postFilter.name.equals("")) {
|
||||||
savePostFilter(originalName);
|
savePostFilter(originalName);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(CustomizePostFilterActivity.this, R.string.post_filter_requires_a_name, Toast.LENGTH_LONG).show();
|
Toast.makeText(CustomizePostFilterActivity.this, R.string.post_filter_requires_a_name, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -627,7 +637,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void constructPostFilter() {
|
private void constructPostFilter() throws PatternSyntaxException {
|
||||||
postFilter.name = nameTextInputEditText.getText().toString();
|
postFilter.name = nameTextInputEditText.getText().toString();
|
||||||
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
|
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
|
||||||
postFilter.minVote = minVoteTextInputEditText.getText() == null || minVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minVoteTextInputEditText.getText().toString());
|
postFilter.minVote = minVoteTextInputEditText.getText() == null || minVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minVoteTextInputEditText.getText().toString());
|
||||||
@ -636,7 +646,9 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
postFilter.maxAwards = maxAwardsTextInputEditText.getText() == null || maxAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxAwardsTextInputEditText.getText().toString());
|
postFilter.maxAwards = maxAwardsTextInputEditText.getText() == null || maxAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxAwardsTextInputEditText.getText().toString());
|
||||||
postFilter.minAwards = minAwardsTextInputEditText.getText() == null || minAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString());
|
postFilter.minAwards = minAwardsTextInputEditText.getText() == null || minAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString());
|
||||||
postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString();
|
postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString();
|
||||||
|
Pattern.compile(postFilter.postTitleExcludesRegex);
|
||||||
postFilter.postTitleContainsRegex = titleContainsRegexTextInputEditText.getText().toString();
|
postFilter.postTitleContainsRegex = titleContainsRegexTextInputEditText.getText().toString();
|
||||||
|
Pattern.compile(postFilter.postTitleContainsRegex);
|
||||||
postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString();
|
postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString();
|
||||||
postFilter.postTitleContainsStrings = titleContainsStringsTextInputEditText.getText().toString();
|
postFilter.postTitleContainsStrings = titleContainsStringsTextInputEditText.getText().toString();
|
||||||
postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString();
|
postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString();
|
||||||
|
@ -12,6 +12,7 @@ import androidx.room.PrimaryKey;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.post.Post;
|
import ml.docilealligator.infinityforreddit.post.Post;
|
||||||
|
|
||||||
@ -173,17 +174,23 @@ public class PostFilter implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (postFilter.postTitleExcludesRegex != null && !postFilter.postTitleExcludesRegex.equals("")) {
|
if (postFilter.postTitleExcludesRegex != null && !postFilter.postTitleExcludesRegex.equals("")) {
|
||||||
Pattern pattern = Pattern.compile(postFilter.postTitleExcludesRegex);
|
try {
|
||||||
Matcher matcher = pattern.matcher(post.getTitle());
|
Pattern pattern = Pattern.compile(postFilter.postTitleExcludesRegex);
|
||||||
if (matcher.find()) {
|
Matcher matcher = pattern.matcher(post.getTitle());
|
||||||
return false;
|
if (matcher.find()) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
} catch (PatternSyntaxException ignore) {}
|
||||||
}
|
}
|
||||||
if (postFilter.postTitleContainsRegex != null && !postFilter.postTitleContainsRegex.equals("")) {
|
if (postFilter.postTitleContainsRegex != null && !postFilter.postTitleContainsRegex.equals("")) {
|
||||||
Pattern pattern = Pattern.compile(postFilter.postTitleContainsRegex);
|
try {
|
||||||
Matcher matcher = pattern.matcher(post.getTitle());
|
Pattern pattern = Pattern.compile(postFilter.postTitleContainsRegex);
|
||||||
if (!matcher.find()) {
|
Matcher matcher = pattern.matcher(post.getTitle());
|
||||||
return false;
|
if (!matcher.find()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (postFilter.postTitleExcludesStrings != null && !postFilter.postTitleExcludesStrings.equals("")) {
|
if (postFilter.postTitleExcludesStrings != null && !postFilter.postTitleExcludesStrings.equals("")) {
|
||||||
|
@ -1308,4 +1308,6 @@
|
|||||||
<string name="exo_controls_volume_up_description">Volume Up</string>
|
<string name="exo_controls_volume_up_description">Volume Up</string>
|
||||||
<string name="exo_controls_volume_off_description">Volume Off</string>
|
<string name="exo_controls_volume_off_description">Volume Off</string>
|
||||||
|
|
||||||
|
<string name="invalid_regex">Invalid regex pattern</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user