Fix invalid utf8 not being detected

- Rusqlite was returning a different error
- The sort field may also contain invalid utf8
This commit is contained in:
Damien Elmes 2022-11-21 23:15:04 +10:00
parent 79f94d5a71
commit ade2738458
2 changed files with 10 additions and 1 deletions

View File

@ -53,6 +53,15 @@ impl From<Error> for AnkiError {
info: reason.to_owned(),
};
}
} else if let Error::FromSqlConversionFailure(_, _, err) = &err {
if let Some(_err) = err.downcast_ref::<Utf8Error>() {
return AnkiError::DbError {
source: DbError {
info: "".to_string(),
kind: DbErrorKind::Utf8,
},
};
}
}
AnkiError::DbError {
source: DbError {

View File

@ -150,7 +150,7 @@ impl super::SqliteStorage {
let fixed_flds: Vec<u8> = 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],
)
},