Merge "Fixing DatabaseUtils to detect malformed UTF-16 strings" into rvc-dev am: 0dcc5c6eb5 am: 799e127b0b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24057913 Change-Id: Ic345ae053cef19329022e5a185e136b66298a12a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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 (c == '\'') {
|
||||
sb.append('\'');
|
||||
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;
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
} else
|
||||
sb.append(sqlString);
|
||||
if (Character.isLowSurrogate(c)) {
|
||||
continue;
|
||||
}
|
||||
if (c == '\'') {
|
||||
sb.append('\'');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append('\'');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user