Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 566546a1 authored by Isc's avatar Isc Committed by Niedermann IT-Dienstleistungen
Browse files

Bug fixed 846: Use Pattern.quote method to force that the searchQuery is a...

Bug fixed 846: Use Pattern.quote method to force that the searchQuery is a literal string instead of the reserved keyword in regex
parent d4f59694
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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);