Skip to content

Commit 720eec9

Browse files
committed
Test crash scenario due to Unicode emoji characters (sqlcipher/android-database-sqlcipher#199)
1 parent e8c1552 commit 720eec9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/net/zetetic/tests/UnicodeTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
import android.database.Cursor;
44
import net.sqlcipher.database.SQLiteDatabase;
5+
import net.sqlcipher.database.SQLiteStatement;
56

67
public class UnicodeTest extends SQLCipherTest {
78
@Override
89
public boolean execute(SQLiteDatabase database) {
9-
1010
String expected = "КАКОЙ-ТО КИРИЛЛИЧЕСКИЙ ТЕКСТ"; // SOME Cyrillic TEXT
1111
String actual = "";
12+
1213
Cursor result = database.rawQuery("select UPPER('Какой-то кириллический текст') as u1", new String[]{});
13-
if(result != null){
14+
if (result != null) {
1415
result.moveToFirst();
1516
actual = result.getString(0);
1617
result.close();
1718
}
18-
return actual.equals(expected);
19+
if (!actual.equals(expected)) return false;
20+
21+
if (android.os.Build.VERSION.SDK_INT >= 23) { // Android M
22+
// This will crash on Android releases 1.X-5.X due the following Android bug:
23+
// https://code.google.com/p/android/issues/detail?id=81341
24+
SQLiteStatement st = database.compileStatement("SELECT '\uD83D\uDE03'"); // SMILING FACE (MOUTH OPEN)
25+
String res = st.simpleQueryForString();
26+
if (!res.equals("\uD83D\uDE03")) return false;
27+
}
28+
29+
// all ok:
30+
return true;
1931
}
2032

2133
@Override

0 commit comments

Comments
 (0)