aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-26 21:42:32 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-26 21:42:32 -0800
commitc65c320b09c795cb27523ff61eb9f9d92663c8cd (patch)
tree820f29b4d48bf1195bf310eea78b8c185218dc18
parenta53ed1bde10de5a70197db5e55e966b634034a6f (diff)
downloadbun-c65c320b09c795cb27523ff61eb9f9d92663c8cd.tar.gz
bun-c65c320b09c795cb27523ff61eb9f9d92663c8cd.tar.zst
bun-c65c320b09c795cb27523ff61eb9f9d92663c8cd.zip
[bun:sqlite] Fix bug with latin1 supplemental characters
Fixes https://github.com/oven-sh/bun/issues/1553
-rw-r--r--src/bun.js/bindings/sqlite/JSSQLStatement.cpp7
-rw-r--r--test/bun.js/sqlite.test.js26
2 files changed, 31 insertions, 2 deletions
diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
index 524c131af..9873bd400 100644
--- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
+++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
@@ -286,10 +286,13 @@ static inline bool rebindValue(JSC::JSGlobalObject* lexicalGlobalObject, sqlite3
return false;
}
- if (roped.is8Bit()) {
+ if (roped.is8Bit() && roped.isAllASCII()) {
CHECK_BIND(sqlite3_bind_text(stmt, i, reinterpret_cast<const char*>(roped.characters8()), roped.length(), transientOrStatic));
- } else {
+ } else if (!roped.is8Bit()) {
CHECK_BIND(sqlite3_bind_text16(stmt, i, roped.characters16(), roped.length() * 2, transientOrStatic));
+ } else {
+ auto utf8 = roped.utf8();
+ CHECK_BIND(sqlite3_bind_text(stmt, i, utf8.data(), utf8.length(), SQLITE_TRANSIENT));
}
} else if (UNLIKELY(value.isHeapBigInt())) {
diff --git a/test/bun.js/sqlite.test.js b/test/bun.js/sqlite.test.js
index 2bf7fc72d..882454fb8 100644
--- a/test/bun.js/sqlite.test.js
+++ b/test/bun.js/sqlite.test.js
@@ -494,3 +494,29 @@ it("inlineCapacity #987", async () => {
expect(Object.keys(db.query(query).all()[0]).length).toBe(99);
});
+
+// https://github.com/oven-sh/bun/issues/1553
+it("latin1 supplement chars", () => {
+ const db = new Database();
+ db.run(
+ "CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, greeting TEXT)",
+ );
+ db.run("INSERT INTO foo (greeting) VALUES (?)", "Welcome to bun!");
+ db.run("INSERT INTO foo (greeting) VALUES (?)", "Español");
+ db.run("INSERT INTO foo (greeting) VALUES (?)", "¿Qué sucedió?");
+
+ expect(db.query("SELECT * FROM foo").all()).toEqual([
+ {
+ id: 1,
+ greeting: "Welcome to bun!",
+ },
+ {
+ id: 2,
+ greeting: "Español",
+ },
+ {
+ id: 3,
+ greeting: "¿Qué sucedió?",
+ },
+ ]);
+});