Merge "Fixing DatabaseUtils to detect malformed UTF-16 strings" into rvc-dev am: 0dcc5c6eb5 am: 799e127b0b am: ddc2eb9d24
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24057913 Change-Id: I0eb4d141dcfc58ca59edcc2dc1fe1bd2cc55c3cf 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) {
|
public static void appendEscapedSQLString(StringBuilder sb, String sqlString) {
|
||||||
sb.append('\'');
|
sb.append('\'');
|
||||||
if (sqlString.indexOf('\'') != -1) {
|
|
||||||
int length = sqlString.length();
|
int length = sqlString.length();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
char c = sqlString.charAt(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 == '\'') {
|
if (c == '\'') {
|
||||||
sb.append('\'');
|
sb.append('\'');
|
||||||
}
|
}
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
sb.append(sqlString);
|
|
||||||
sb.append('\'');
|
sb.append('\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user