Skip to content

Commit 8bddd45

Browse files
r10slink2xt
andauthored
fix: accept QR codes with 'broken' JSON (#6528)
this converts old QR codes to the new format, in an hacky, but simple way, see #6518 for more details and for code snippet then QR code change is esp. bad as ppl will have different versions for some days at least, weakening overall UX, esp. of first-time-users that may come to delta because of praised, seamless multidevice ... :) i tested in deltachat/deltachat-ios#2595 that this actually fixes the problem, and there is no deeper issue with changed chashes or so - seemed not to be the case, at least, with this hack, core accepts QR codes from the released 1.52-and-before series this hack gives user time to update, it can be removed after some months (we can also remove the old BACKUP qr code alltogether then) we should still not wait too long with the PR as there are already versions out with the "new/bad" QR code (and growing, as new iOS installations will get the new format, one cannot revert a version, only pause rollout) --------- Co-authored-by: link2xt <link2xt@testrun.org>
1 parent a0ff0d7 commit 8bddd45

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/qr.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ pub enum Qr {
261261
},
262262
}
263263

264+
// hack around the changed JSON accidentally used by an iroh upgrade, see #6518 for more details and for code snippet.
265+
// this hack is mainly needed to give ppl time to upgrade and can be removed after some months (added 2025-02)
266+
fn fix_add_second_device_qr(qr: &str) -> String {
267+
qr.replacen(r#","info":{"relay_url":"#, r#","relay_url":"#, 1)
268+
.replacen(r#""]}}"#, r#""]}"#, 1)
269+
}
270+
264271
fn starts_with_ignore_case(string: &str, pattern: &str) -> bool {
265272
string.to_lowercase().starts_with(&pattern.to_lowercase())
266273
}
@@ -290,7 +297,8 @@ pub async fn check_qr(context: &Context, qr: &str) -> Result<Qr> {
290297
} else if qr.starts_with(SHADOWSOCKS_SCHEME) {
291298
decode_shadowsocks_proxy(qr)?
292299
} else if starts_with_ignore_case(qr, DCBACKUP2_SCHEME) {
293-
decode_backup2(qr)?
300+
let qr_fixed = fix_add_second_device_qr(qr);
301+
decode_backup2(&qr_fixed)?
294302
} else if qr.starts_with(MAILTO_SCHEME) {
295303
decode_mailto(context, qr).await?
296304
} else if qr.starts_with(SMTP_SCHEME) {

src/qr/qr_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,5 +914,8 @@ async fn test_decode_backup() -> Result<()> {
914914
let qr = check_qr(&ctx, r#"DCBACKUP2:TWSv6ZjDPa5eoxkocj7xMi8r&{"node_id":"9afc1ea5b4f543e5cdd7b7a21cd26aee7c0b1e1c2af26790896fbd8932a06e1e","relay_url":null,"direct_addresses":["192.168.1.10:12345"]}"#).await?;
915915
assert!(matches!(qr, Qr::Backup2 { .. }));
916916

917+
let qr = check_qr(&ctx, r#"DCBACKUP2:AIvFjRFBt_aMiisSZ8P33JqY&{"node_id":"buzkyd4x76w66qtanjk5fm6ikeuo4quletajowsl3a3p7l6j23pa","info":{"relay_url":null,"direct_addresses":["192.168.1.5:12345"]}}"#).await?;
918+
assert!(matches!(qr, Qr::Backup2 { .. }));
919+
917920
Ok(())
918921
}

0 commit comments

Comments
 (0)