Skip to content

Commit 252751d

Browse files
delagensimolus3
authored andcommitted
fix escaping of encryptionKey (#1016)
1 parent 2f10425 commit 252751d

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

demos/example-node/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ const main = async () => {
4545
openWorker: customWorker,
4646
initializeConnection: async (db) => {
4747
if (encryptionKey.length) {
48-
const escapedKey = encryptionKey.replace("'", "''");
49-
await db.execute(`pragma key = '${escapedKey}'`);
48+
const escapedKey = encryptionKey.replaceAll("'", "''");
49+
await db.execute(`PRAGMA key = '${escapedKey}'`);
5050
}
5151

5252
// Make sure the database is readable, this fails early if the key is wrong.
53-
await db.execute('pragma user_version');
53+
await db.execute('PRAGMA user_version');
5454
}
5555
},
5656
logger

packages/node/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ const db = new PowerSyncDatabase({
141141
},
142142
initializeConnection: async (db) => {
143143
if (encryptionKey.length) {
144-
const escapedKey = encryptionKey.replace("'", "''");
145-
await db.execute(`pragma key = '${escapedKey}'`);
144+
const escapedKey = encryptionKey.replaceAll("'", "''");
145+
await db.execute(`PRAGMA key = '${escapedKey}'`);
146146
}
147147

148148
// Make sure the database is readable, this fails early if the key is wrong.
149-
await db.execute('pragma user_version');
149+
await db.execute('PRAGMA user_version');
150150
}
151151
},
152152
logger

packages/web/src/db/adapters/wa-sqlite/RawSqliteConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class RawSqliteConnection {
5555
);
5656
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
5757
if (this.options.encryptionKey) {
58-
const escapedKey = this.options.encryptionKey.replace("'", "''");
59-
await this.executeRaw(`PRAGMA key = '${escapedKey}'`);
58+
const escapedKey = this.options.encryptionKey.replaceAll("'", "''");
59+
await this.executeRaw(`PRAGMA key = '${escapedKey}';`);
6060
}
6161
await this.executeRaw(`PRAGMA cache_size = -${this.options.cacheSizeKb};`);
6262

0 commit comments

Comments
 (0)