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

Commit a5083c40 authored by Felipe Leme's avatar Felipe Leme
Browse files

CharSequenceTransformation should not change anything when comparision fails.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases -t android.autofillservice.cts.CharSequenceTransformationTest#testMismatch
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases

Fixes: 64482785

Change-Id: Ia6036e0a1c6f5f084e6b13c7bdd3a9e24be7ac1a
parent bca04aca
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.widget.TextView;

import com.android.internal.util.Preconditions;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
@@ -53,7 +54,8 @@ import java.util.regex.Pattern;
 * fields (month and year) would be:
 *
 * <pre class="prettyprint">
 * new CharSequenceTransformation.Builder(ccExpMonthId, Pattern.compile("^(\\d\\d)$"), "Exp: $1")
 * new CharSequenceTransformation
 *   .Builder(ccExpMonthId, Pattern.compile("^(\\d\\d)$"), "Exp: $1")
 *   .addField(ccExpYearId, Pattern.compile("^(\\d\\d\\d\\d)$"), " / $1");
 * </pre>
 */
@@ -83,8 +85,13 @@ public final class CharSequenceTransformation extends InternalTransformation imp
                return;
            }
            try {
                final Matcher matcher = field.first.matcher(value);
                if (!matcher.matches()) {
                    if (sDebug) Log.d(TAG, "match for " + field.first + " failed on id " + id);
                    return;
                }
                // replaceAll throws an exception if the subst is invalid
                final String convertedValue = field.first.matcher(value).replaceAll(field.second);
                final String convertedValue = matcher.replaceAll(field.second);
                converted.append(convertedValue);
            } catch (Exception e) {
                // Do not log full exception to avoid PII leaking
+1 −2
Original line number Diff line number Diff line
@@ -78,8 +78,7 @@ public final class ImageTransformation extends InternalTransformation implements
        }
        final int size = mOptions.size();
        if (sDebug) {
            Log.d(TAG, size + " multiple options on id " + childViewId + " to compare against "
                    + value);
            Log.d(TAG, size + " multiple options on id " + childViewId + " to compare against");
        }

        for (int i = 0; i < size; i++) {