Android Room FTS4 Crash

What is causing error

I tried to search with a query that starts with - or " but Rx chain did return error:

SQLiteException: malformed MATCH expression

This means that in Room (at least in version 2.2.3) Room does nothing to the querry typed by a user.

How to fix that

Sanitize query from user to protect Database and Rx chain.

private fun sanitizeQuery(query: String): String {
    val queryWithEscapedQuotes = "*$query*".replace(Regex.fromLiteral("\""), "\"\"")
    return "\"$queryWithEscapedQuotes\""
}

Source: sqlite.org