avioli / uni_links

Flutter plugin for accepting incoming links.
BSD 2-Clause "Simplified" License
564 stars 317 forks source link

getUriLinksStream() error when the path has '&' #100

Closed shadow1007 closed 3 years ago

shadow1007 commented 3 years ago

I'm using [custom schemes] and am testing on my [Android Emulator], which is running [Android 9].

My code in AndroidManifest.xml

                <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                  android:scheme="myapp"
                  android:host="action"
                  />
                 </intent-filter>

and in .dart

      _sub = getUriLinksStream().listen((Uri uri) {
      print(uri.queryParameters);
    }, onError: (err) {
      // Handle exception by warning the user their action did not succeed
    });

I run the command in treminal adb shell 'am start -W -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "mayapp://action?article=1&lang=en#test"'

my expected result

got link: mayapp://action?article=1&lang=en#test
{article: 1,lang: en}

But what I got is

got link: mayapp://action?article=1
{article: 1}

My flutter verion

[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.53.2)
[√] Connected device (1 available)

When I only add one query parameter, every thing is fine. But when I using '&' in the path, it seen that is ignore all the thing after '&'

I try to use URL encode to replace "&" with "%26" But the result is

got link: mayapp://action?article=1%26lang=en#test
{article: 1&lang=en}

Am I do anything wrong with the package?

shadow1007 commented 3 years ago

I find out a solution

I try to use URL encode to replace "&" with "%26" adb shell 'am start -W -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "mayapp://action?article=1%26lang=en#test"'

Then, in Dart I decode the path string:

    _sub = getLinksStream().listen((String link) {
      var uri = Uri.parse(link.replaceAll("%26", "&"));
      print(uri.queryParameters);
    }, onError: (err) {
      // Handle exception by warning the user their action did not succeed
    });

What I got

got link: mayapp://action?article=1%26lang=en#test
 {article: 1, lang: en}
jscarl commented 3 years ago

Same here, but your solution it's quite strange. In my case, I used the latest version, if I simulate mayapp://action?article=1%26lang=en#test it would be mayapp://action?article=1%2625lang=en#test.

shadow1007 commented 3 years ago

Same here, but your solution it's quite strange. In my case, I used the latest version, if I simulate mayapp://action?article=1%26lang=en#test it would be mayapp://action?article=1%2625lang=en#test.

Since it does not accept special character like &, therefore I use URL encode to encode it. All special character in URL will look like %xx. It the app, the received link should be decoded base on URL encode. Like, the %26 should be replace by &. It the only way I know so far, bro.