From 09c33c8deb37c9639f8dad148442bc153de46955 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Fri, 31 May 2024 10:14:05 -0500 Subject: [PATCH] Handle special chars in password --- src/db.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/db.rs b/src/db.rs index 030e058..7c72e18 100644 --- a/src/db.rs +++ b/src/db.rs @@ -377,8 +377,8 @@ impl diesel::r2d2::CustomizeConnection { fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), diesel::r2d2::Error> { (|| { - // FIXME: Special characters might fuck up - conn.batch_execute(&format!("PRAGMA key={}", self.key))?; + let password = self.key.as_str().replace("'", "''"); + conn.batch_execute(&format!("PRAGMA key='{password}'"))?; if self.enable_wal { conn.batch_execute("PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;")?; } @@ -415,7 +415,7 @@ mod tests { use std::str::FromStr; use tempdir::TempDir; - const DEFAULT_PASSWORD: &str = "test"; + const DEFAULT_PASSWORD: &str = "p.a$$w0rd!'x"; const FEDERATION_ID: &str = "c8d423964c7ad944d30f57359b6e5b260e211dcfdb945140e28d4df51fd572d2"; fn setup_test_db() -> Arc {