From 41c33003ac06f4d4dc6b9e234dc7380db54f1ec6 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Sat, 28 Jan 2023 18:27:59 +0530 Subject: [PATCH] Fix: Url decode the path value --- lib/models/code.dart | 6 ++++-- test/models/code_test.dart | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/models/code_test.dart diff --git a/lib/models/code.dart b/lib/models/code.dart index 2fd775958..89e10d947 100644 --- a/lib/models/code.dart +++ b/lib/models/code.dart @@ -67,7 +67,8 @@ class Code { static String _getAccount(Uri uri) { try { - return uri.path.split(':')[1]; + final String path = Uri.decodeComponent(uri.path); + return path.split(':')[1]; } catch (e) { return ""; } @@ -75,7 +76,8 @@ class Code { static String _getIssuer(Uri uri) { try { - return uri.path.split(':')[0].substring(1); + final String path = Uri.decodeComponent(uri.path); + return path.split(':')[0].substring(1); } catch (e) { return ""; } diff --git a/test/models/code_test.dart b/test/models/code_test.dart new file mode 100644 index 000000000..c61122292 --- /dev/null +++ b/test/models/code_test.dart @@ -0,0 +1,13 @@ +import 'package:ente_auth/models/code.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test("parseCodeFromRawData", () { + final code1 = Code.fromRawData( + "otpauth://totp/example%20finance%3Aee%40ff.gg?secret=ASKZNWOU6SVYAMVS", + ); + expect(code1.issuer, "example finance"); + expect(code1.account, "ee@ff.gg"); + expect(code1.secret, "ASKZNWOU6SVYAMVS"); + }); +}