Ver Fonte

Fix: Url decode the path value

Neeraj Gupta há 2 anos atrás
pai
commit
41c33003ac
2 ficheiros alterados com 17 adições e 2 exclusões
  1. 4 2
      lib/models/code.dart
  2. 13 0
      test/models/code_test.dart

+ 4 - 2
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 "";
     }

+ 13 - 0
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");
+  });
+}