diff options
-rw-r--r-- | src/bun.js/bindings/sqlite/JSSQLStatement.cpp | 8 | ||||
-rw-r--r-- | test/js/bun/sqlite/sqlite.test.js | 36 |
2 files changed, 40 insertions, 4 deletions
diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp index d42f01019..8519cb2e2 100644 --- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp +++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp @@ -1107,11 +1107,11 @@ static inline JSC::JSValue constructResultObject(JSC::JSGlobalObject* lexicalGlo if (len > 64) { value = JSC::JSValue::decode(Bun__encoding__toStringUTF8(text, len, lexicalGlobalObject)); - continue; + break; + } else { + value = jsString(vm, WTF::String::fromUTF8(text, len)); + break; } - - value = jsString(vm, WTF::String::fromUTF8(text, len)); - break; } case SQLITE_BLOB: { size_t len = sqlite3_column_bytes(stmt, i); diff --git a/test/js/bun/sqlite/sqlite.test.js b/test/js/bun/sqlite/sqlite.test.js index e4725cac2..7998f7469 100644 --- a/test/js/bun/sqlite/sqlite.test.js +++ b/test/js/bun/sqlite/sqlite.test.js @@ -553,3 +553,39 @@ describe("Database.run", () => { } }); }); + +it("#3991", () => { + const db = new Database(":memory:"); + db.prepare( + `CREATE TABLE IF NOT EXISTS users ( + id TEXT PRIMARY KEY, + xx TEXT) +`, + ).run(); + + db.prepare( + `insert into users (id, xx) values ( + 'foobar', + '{ + "links": [{"1": { + "2": "https://foobar.to/123", + "3": "4" + }}] + + }' +)`, + ).run(); + + let x = db + .query( + `SELECT * FROM users + WHERE users.id = 'foobar' + limit 1`, + ) + .get(); + + // Check we don't crash when a column with a string value greater than 64 characters is present. + expect(x.abc).toBeUndefined(); + + expect(x.id).toBe("foobar"); +}); |