Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kuery not escaping apostrophe characters in Insert queries #141

Open
NocturnalSolutions opened this issue Jun 9, 2018 · 1 comment
Open

Comments

@NocturnalSolutions
Copy link
Contributor

NocturnalSolutions commented Jun 9, 2018

This seems like a big one; surely I'm not the first to notice this…? But I don't see any mention of it elsewhere in this issue queue… Is it expected that we need to escape apostrophes ourselves?

I was seeing insert queries fail, and I narrowed it down to the failure happening when one of the fields I was trying to insert to contained an apostrophe. By examining the compiled queries, I confirmed that Kuery is not escaping the apostrophe in its compiled insert queries. Here's a sample insert query that caused a failure when I had just a single apostrophe character in the relevant field ("raw") when using SQLite:

INSERT INTO "pastes" ("uuid", "date", "raw", "mode") VALUES ('3229439B-A6BC-4D91-BCF8-955BFA0717EC', '2018-06-09T03:27:12Z', ''', '_plain_')

I thought it might be just an SQLite thing so I rejiggered my app to work with MySQL. The resulting query is slightly different, but the failure is still there:

INSERT INTO `pastes` (`uuid`, `date`, `raw`, `mode`) VALUES ('7A90E481-F3BD-4708-B1F5-77B41ECFC767', '2018-06-09T03:44:04Z', ''', 'objectivec')

Here's the code constructing the Insert object:

        let i = Insert(into: pasteTable, valueTuples: [
            (pasteTable.uuid, uuid.uuidString),
            (pasteTable.date, ISO8601DateFormatter().string(from: Date())),
            (pasteTable.raw, raw),
            (pasteTable.mode, mode)
        ])

Not patching this myself because, one, it's late here and I'm not actually living up to my username very well recently, and two, again, this seems like such an obvious bug that I'm not sure it wasn't intentional…? But if the latter isn't the case, I'll throw something together and make a PR.

@kilnerm
Copy link
Contributor

kilnerm commented Jun 11, 2018

I am in agreement that this is a bug.

If you are happy to put together a PR with a fix then it would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants