From ade27384586337fe934aaf4714230c893a46932e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 21 Nov 2022 23:15:04 +1000 Subject: [PATCH] Fix invalid utf8 not being detected - Rusqlite was returning a different error - The sort field may also contain invalid utf8 --- rslib/src/error/db.rs | 9 +++++++++ rslib/src/storage/note/mod.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rslib/src/error/db.rs b/rslib/src/error/db.rs index 323017830..36946ee23 100644 --- a/rslib/src/error/db.rs +++ b/rslib/src/error/db.rs @@ -53,6 +53,15 @@ impl From for AnkiError { info: reason.to_owned(), }; } + } else if let Error::FromSqlConversionFailure(_, _, err) = &err { + if let Some(_err) = err.downcast_ref::() { + return AnkiError::DbError { + source: DbError { + info: "".to_string(), + kind: DbErrorKind::Utf8, + }, + }; + } } AnkiError::DbError { source: DbError { diff --git a/rslib/src/storage/note/mod.rs b/rslib/src/storage/note/mod.rs index 45b000705..d74db2d45 100644 --- a/rslib/src/storage/note/mod.rs +++ b/rslib/src/storage/note/mod.rs @@ -150,7 +150,7 @@ impl super::SqliteStorage { let fixed_flds: Vec = row.get(0)?; let fixed_str = String::from_utf8_lossy(&fixed_flds); self.db.execute( - "update notes set flds = ? where id = ?", + "update notes set flds = ?, sfld = '' where id = ?", params![fixed_str, nid], ) },