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

Make SQLite VTable module name comparison case-insensitive #1762

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/workerd/api/sql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,27 @@ async function test(storage) {
assert.throws(() => sql.exec('BEGIN TRANSACTION'), /not authorized/)
assert.throws(() => sql.exec('SAVEPOINT foo'), /not authorized/)

// Full text search extension
// Virtual tables
// Only fts5 module is allowed
assert.throws(
() => sql.exec(`CREATE VIRTUAL TABLE test_fts USING fts5abcd(id);`),
/not authorized/
)

// Full text search extension
sql.exec(`
CREATE TABLE documents (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL
);
`)

// Module name is case-insensitive
sql.exec(`
CREATE VIRTUAL TABLE documents_fts USING fts5(id, title, content, tokenize = porter);
CREATE VIRTUAL TABLE documents_fts USING FtS5(id, title, content, tokenize = porter);
`)

sql.exec(`
CREATE TRIGGER documents_fts_insert
AFTER INSERT ON documents
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/util/sqlite.c++
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#if _WIN32
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif

namespace workerd {
Expand Down Expand Up @@ -655,7 +656,7 @@ bool SqliteDatabase::isAuthorized(int actionCode,
// Virtual tables are tables backed by some native-code callbacks. We don't support these except for FTS5 (Full Text Search) https://www.sqlite.org/fts5.html
{
KJ_IF_SOME (moduleName, param2) {
if (moduleName == "fts5") {
if (strcasecmp(moduleName.begin(), "fts5") == 0) {
return true;
}
}
Expand Down
Loading