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

Commit 8a0d2662 authored by Kunal Malhotra's avatar Kunal Malhotra Committed by Automerger Merge Worker
Browse files

Merge "Fixing DatabaseUtils to detect malformed UTF-16 strings" into udc-dev...

Merge "Fixing DatabaseUtils to detect malformed UTF-16 strings" into udc-dev am: 24cc1544 am: 71c7da3b am: 80ca16da

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23545766



Change-Id: I98415997f78a4b93e23028075c6d2289ae50321e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4e22023f 80ca16da
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -511,17 +511,31 @@ public class DatabaseUtils {
     */
    public static void appendEscapedSQLString(StringBuilder sb, String sqlString) {
        sb.append('\'');
        if (sqlString.indexOf('\'') != -1) {
        int length = sqlString.length();
        for (int i = 0; i < length; i++) {
            char c = sqlString.charAt(i);
            if (Character.isHighSurrogate(c)) {
                if (i == length - 1) {
                    continue;
                }
                if (Character.isLowSurrogate(sqlString.charAt(i + 1))) {
                    // add them both
                    sb.append(c);
                    sb.append(sqlString.charAt(i + 1));
                    continue;
                } else {
                    // this is a lone surrogate, skip it
                    continue;
                }
            }
            if (Character.isLowSurrogate(c)) {
                continue;
            }
            if (c == '\'') {
                sb.append('\'');
            }
            sb.append(c);
        }
        } else
            sb.append(sqlString);
        sb.append('\'');
    }