fix: add tolerance for macOS and iOS changing # to %23

fixes #1969

Bug description:
macOS and iOS sometimes replace the # with %23 (uri encode it), we should be able to parse this wrong format too, see issue https://github.com/deltachat/deltachat-core-rust/issues/1969 for more info
This commit is contained in:
Simon Laux
2024-01-24 22:42:48 +01:00
committed by Simon Laux
parent 73d612a07d
commit 0afc0dd65a

View File

@@ -301,11 +301,12 @@ pub fn format_backup(qr: &Qr) -> Result<String> {
async fn decode_openpgp(context: &Context, qr: &str) -> Result<Qr> { async fn decode_openpgp(context: &Context, qr: &str) -> Result<Qr> {
let payload = &qr[OPENPGP4FPR_SCHEME.len()..]; let payload = &qr[OPENPGP4FPR_SCHEME.len()..];
let (fingerprint, fragment) = match payload.find('#').map(|offset| { // macOS and iOS sometimes replace the # with %23 (uri encode it), we should be able to parse this wrong format too.
let (fp, rest) = payload.split_at(offset); // see issue https://github.com/deltachat/deltachat-core-rust/issues/1969 for more info
// need to remove the # from the fragment let (fingerprint, fragment) = match payload
(fp, &rest[1..]) .split_once('#')
}) { .or_else(|| payload.split_once("%23"))
{
Some(pair) => pair, Some(pair) => pair,
None => (payload, ""), None => (payload, ""),
}; };
@@ -943,6 +944,21 @@ mod tests {
Ok(()) Ok(())
} }
// macOS and iOS sometimes replace the # with %23 (uri encode it), we should be able to parse this wrong format too.
// see issue https://github.com/deltachat/deltachat-core-rust/issues/1969 for more info
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_decode_openpgp_tolerance_for_issue_1969() -> Result<()> {
let ctx = TestContext::new().await;
let qr = check_qr(
&ctx.ctx,
"OPENPGP4FPR:79252762C34C5096AF57958F4FC3D21A81B0F0A7%23a=cli%40deltachat.de&g=test%20%3F+test%20%21&x=h-0oKQf2CDK&i=9JEXlxAqGM0&s=0V7LzL9cxRL"
).await?;
assert!(matches!(qr, Qr::AskVerifyGroup { .. }));
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_decode_openpgp_group() -> Result<()> { async fn test_decode_openpgp_group() -> Result<()> {
let ctx = TestContext::new().await; let ctx = TestContext::new().await;