-
Notifications
You must be signed in to change notification settings - Fork 144
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
Single quote in value results in SQLITE_ERROR #256
Comments
@dshepsis can you pas it like this |
This doesn't work for a few reasons. Of course, just using a single backslash has no effect because the single quote is already a literal in this case. In other words, the following code produces exactly the same result as the code in the original report: const Keyv = require('keyv');
const testDB = new Keyv('sqlite://test.sqlite', { namespace: 'test' });
testDB.on('error', err => console.log('Connection Error', err));
const value = "\'";
testDB.set('key', value); If you instead use a double backslash This isn't an acceptable workaround either, because I'm trying to store objects instead of strings. To escape everything would require iterating through every single key and value of the object, recursively, to double-up every single quote. Also, this means that anyone trying to pass in strings/objects which already contain double single quotes (for whatever reason) are having their data silently modified by keyv. It's also worth mentioning that the key passed into the const Keyv = require('keyv');
const testDB = new Keyv('sqlite://test.sqlite', { namespace: 'test' });
testDB.on('error', err => console.log('Connection Error', err));
const value = 'foo';
testDB.set('\'', value); Results in the error:
This can be avoided using double single quotes in the key (both when using |
Implemented pkgRelPath to make sure that paths to local package resources are consistent and reliable regardless of node's current working directory. guildConfig is meant to mimic the get and set API of Keyv, but write to a directory of JSON files instead of a single sqlite database. This may cost performance, but should make things easier to maintain, as well as avoid the bug with single quote sanitization (jaredwray/keyv#256).
Why was this closed? |
Sorry as this was a mistake and we are looking into it how to test for this scenario and resolve it. :-) |
@dshepsis - wanted to update that we are working on moving back to sqlite3 which should help resolve this issue. |
We will have a newer version of sqlite coming in the next week or so that should be based on sqlite3. FYI. |
This should be resolved with the following version |
Problem
When using
Keyv#set
, an error is thrown if thevalue
contains a string containing a single quote.For example, if the string is simply a single quote, the error is:
How to reproduce
Run this demonstration code in a directory with Keyv added as a dependency:
This will result in the above error.
It seems that #210 was supposed to address this issue, but it's either not part of the current release, or failed to fix the issue. Either way, a test case should probably be added for this.
Expected behavior
Values containing single quotes in strings should be serialized normally, like any other values.
Version
4.1.1
The text was updated successfully, but these errors were encountered: