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

Commit 653d3a27 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Limit created string size in Spell Checker

Change-Id: I2f4e7a8b0022d76bc30199ff80c2fe637dbe03ef
parent fb90df8c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -863,6 +863,17 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
        return new String(buf);
    }

    /**
     * Return a String containing a copy of the chars in this buffer, limited to the
     * [start, end[ range.
     * @hide
     */
    public String substring(int start, int end) {
        char[] buf = new char[end - start];
        getChars(start, end, buf, 0);
        return new String(buf);
    }

    private TextWatcher[] sendTextWillChange(int start, int before, int after) {
        TextWatcher[] recip = getSpans(start, start + before, TextWatcher.class);
        int n = recip.length;
+6 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package android.text.method;

import android.text.Selection;
import android.text.SpannableStringBuilder;

import java.text.BreakIterator;
import java.util.Locale;
@@ -58,7 +59,11 @@ public class WordIterator implements Selection.PositionIterator {
        mOffsetShift = Math.max(0, start - WINDOW_WIDTH);
        final int windowEnd = Math.min(charSequence.length(), end + WINDOW_WIDTH);

        mString = charSequence.toString().substring(mOffsetShift, windowEnd);
        if (charSequence instanceof SpannableStringBuilder) {
            mString = ((SpannableStringBuilder) charSequence).substring(mOffsetShift, windowEnd);
        } else {
            mString = charSequence.subSequence(mOffsetShift, windowEnd).toString();
        }
        mIterator.setText(mString);
    }

+4 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.widget;
import android.content.Context;
import android.text.Editable;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.WordIterator;
import android.text.style.SpellCheckSpan;
@@ -239,7 +240,9 @@ public class SpellChecker implements SpellCheckerSessionListener {

            // Do not check this word if the user is currently editing it
            if (start >= 0 && end > start && (selectionEnd < start || selectionStart > end)) {
                final String word = editable.subSequence(start, end).toString();
                final String word = (editable instanceof SpannableStringBuilder) ?
                        ((SpannableStringBuilder) editable).substring(start, end) :
                        editable.subSequence(start, end).toString();
                spellCheckSpan.setSpellCheckInProgress(true);
                textInfos[textInfosCount++] = new TextInfo(word, mCookie, mIds[i]);
            }