Skip to content

Crash when FTS searching with symbols/special characters #855

Closed
@erikbye

Description

@erikbye

I use FTS5 and I get a crash when attempting to search with various symbols, for instance, equal symbol (=).

Error message: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: fts5: syntax error near "=" (code: 1)

Same thing with forward and backslash: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: fts5: syntax error near "\" (code: 1)

File: Statement.swift

extension FailableIterator {
    public func next() -> Element? {
        return try! failableNext()
    }
}

My code:

let fts_results = DBManager.shared.cliptext_virtual.filter(DBManager.shared.cliptext_virtual.match("clip_text: \(searchString)*"))

I also tried without the variable searchString. Just "clip_text: =", escaping the = sign, wrapping it in single quotes, etc.

If I write the query as such: .match("clip_text: \"\(searchString)\"*"))
I no longer get a crash when searching for =, but I don't get a match either, only for words.

bindings: [Optional("clip_text: \"=\"*")]))

How should I go about searching for an exact phrase, containing characters like = and /? Say, the phrase "sum= /"

SQLite.swift version: 0.11.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions