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

Commit ae39bd6c 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 am: 24cc1544

parents 19799ee5 24cc1544
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('\'');
    }