Properly escape query strings, fixed crash

This commit is contained in:
Anthony Restaino 2016-07-22 22:51:40 -04:00
parent a0ae42dbb9
commit cb065d0812

View File

@ -6,8 +6,10 @@ package acr.browser.lightning.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQuery;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -151,8 +153,10 @@ public class HistoryDatabase extends SQLiteOpenHelper {
if (search == null) {
return itemList;
}
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%"
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY "
search = DatabaseUtils.sqlEscapeString('%' + search + '%');
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE "
+ search + " OR " + KEY_URL + " LIKE " + search + " ORDER BY "
+ KEY_TIME_VISITED + " DESC LIMIT 5";
Cursor cursor = mDatabase.rawQuery(selectQuery, null);