mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-26 14:57:38 +03:00
Bug fixed 846: Use Pattern.quote method to force that the searchQuery is a literal string instead of the reserved keyword in regex
This commit is contained in:
parent
d4f59694b5
commit
566546a1da
1 changed files with 3 additions and 2 deletions
|
@ -9,6 +9,7 @@ import android.text.TextUtils;
|
|||
import android.text.format.DateUtils;
|
||||
import android.text.style.BackgroundColorSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -64,7 +65,7 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
|
|||
private DBNote colorTheNote(DBNote dbNote) {
|
||||
if (!TextUtils.isEmpty(searchQuery)) {
|
||||
SpannableString spannableString = new SpannableString(dbNote.getTitle());
|
||||
Matcher matcher = Pattern.compile("(" + searchQuery + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
|
||||
Matcher matcher = Pattern.compile("(" + Pattern.quote(searchQuery.toString()) + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
|
||||
while (matcher.find()) {
|
||||
spannableString.setSpan(new ForegroundColorSpan(searchForeground), matcher.start(), matcher.end(), 0);
|
||||
spannableString.setSpan(new BackgroundColorSpan(searchBackground), matcher.start(), matcher.end(), 0);
|
||||
|
@ -73,7 +74,7 @@ public class LoadNotesListTask extends AsyncTask<Void, Void, List<Item>> {
|
|||
dbNote.setTitle(Html.toHtml(spannableString));
|
||||
|
||||
spannableString = new SpannableString(dbNote.getExcerpt());
|
||||
matcher = Pattern.compile("(" + searchQuery + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
|
||||
matcher = Pattern.compile("(" + Pattern.quote(searchQuery.toString()) + ")", Pattern.CASE_INSENSITIVE).matcher(spannableString);
|
||||
while (matcher.find()) {
|
||||
spannableString.setSpan(new ForegroundColorSpan(searchForeground), matcher.start(), matcher.end(), 0);
|
||||
spannableString.setSpan(new BackgroundColorSpan(searchBackground), matcher.start(), matcher.end(), 0);
|
||||
|
|
Loading…
Reference in a new issue