Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[url_launcher] docs: note about encoding URIs #2172

Merged
merged 19 commits into from
Jun 17, 2020

Conversation

CoreyCole
Copy link
Contributor

@CoreyCole CoreyCole commented Oct 9, 2019

Description

Add a note about encoding URLs passed to the url_launcher in the packages README.

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeFull is not the right API here; if subject contains an ampersand, for instance, you will not get the correct URI. Creating a correctly encoded URI requires knowledge of the structure of the URI you are building, such as what the query components are.

If an example is added, it should be encoding each portion with the correct API. As written, this example encourages people to use the encoding APIs incorrectly.

@collinjackson
Copy link
Contributor

@CoreyCole please let us know if you want to keep working on this PR or if you want to abandon it.

If you do want to have it reviewed, please update the CHANGELOG and pubspec.yaml.

@stuartmorgan-g
Copy link
Contributor

To summarize here some later discussion in a bug, this is what I think a recommendation should look like for mailto if something like this PR goes forward.

Interestingly, since my earlier comment I actually saw a bug go by where someone was getting "incorrect" results because they were putting a URL (unencoded) that itself had query parameters in the body of a mailto URL, providing a real-world example of the concern I raised; encoding that using encodeFull wouldn't help with the fact that the argument parsing didn't do at all what they wanted, while using proper URL construction as in the comment I've linked to here would have done the right thing.

@CoreyCole
Copy link
Contributor Author

Sorry this took me so long to get around to! Hopefully it looks good now.

Happy holidays :)

@CoreyCole
Copy link
Contributor Author

@stuartmorgan I think this documentation PR is ready, but every time I re-run the cirrus build something random fails.

final Uri _emailLaunchUri = Uri(
scheme: 'mailto',
userInfo: 'support',
host: 'flutter.dev',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of userInfo/host here is not correct for mailto, per the comment linked earlier in this discussion. Per your own testing, this would fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that is my mistake, I'm not actively working on the app using the mailto url anymore. Fixed in 854f6a3

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a bunch of specific nits, but at a high level I think adding this to the docs is a good idea given that it's been reported as a bug quite a few times, indicating that many people don't realize it's necessary (and especially given that constructing mailto correctly as a URI required me to go read the core URI spec, so is definitely non-obvious).

I don't think I need to review this again, but a flutter/plugins maintainer should give it a final approval.

@@ -1,3 +1,7 @@
## 5.4.2

* Add documentation suggesting how to encode urls with special characters.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@collinjackson Should this still be revving the version given that it's just a README update now?

@@ -53,6 +53,28 @@ Common schemes supported by both iOS and Android:

More details can be found here for [iOS](https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html) and [Android](https://developer.android.com/guide/components/intents-common.html)

### Encoding URLs

URLs should be safely encoded, espeically when including spaces or other special characters. We can do this using dart's `Uri` helper methods included in `dart:core`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would suggest "must be properly encoded" rather than "should be safely encoded" (it's not really optional, and "safely" is somewhat ambiguous).

@@ -53,6 +53,28 @@ Common schemes supported by both iOS and Android:

More details can be found here for [iOS](https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html) and [Android](https://developer.android.com/guide/components/intents-common.html)

### Encoding URLs

URLs should be safely encoded, espeically when including spaces or other special characters. We can do this using dart's `Uri` helper methods included in `dart:core`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the rest of this README appears to use "we" to mean the plugin maintainers, but this is a step that would be done by clients of the plugin, so it would be clearer to say "This can be done using" rather than "We can do this using".

@@ -53,6 +53,28 @@ Common schemes supported by both iOS and Android:

More details can be found here for [iOS](https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html) and [Android](https://developer.android.com/guide/components/intents-common.html)

### Encoding URLs

URLs should be safely encoded, espeically when including spaces or other special characters. We can do this using dart's `Uri` helper methods included in `dart:core`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "dart"->"Dart". And maybe provide a link rather than just mentioning the library.

Combined with the above, I would suggest changing this whole sentence to:

This can be done using the Uri class:


// ...

launch(_emailLaunchString);
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe collapse this last section to just:

launch(_emailLaunchUri.toString());

Extracting it to a variable if someone wants to do other things with the string first is something they can do trivially, so having shorter example code seems like the better option.

@stuartmorgan-g
Copy link
Contributor

but every time I re-run the cirrus build something random fails

Don't worry about that part; once it's ready to go whoever is landing it can deal with the infrastructure flake.

@stuartmorgan-g stuartmorgan-g requested review from cyanglaz and removed request for collinjackson June 7, 2020 01:48
@stuartmorgan-g
Copy link
Contributor

@cyanglaz Can you give this a review? This continues to be a source of confusion and bug reports, and it would be really good to have something in the readme about it.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stuartmorgan-g
Copy link
Contributor

@CoreyCole Now that this has all the approvals it needs, if you update to the latest master and resolve the conflicts, I can land and publish it.

@CoreyCole
Copy link
Contributor Author

Done. I removed the version bump because this is only a documentation change as @stuartmorgan stated

@CoreyCole
Copy link
Contributor Author

On second thought, it looks like the version has been bumped in the past for README changes. I bumped the version to 5.4.11.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bearing with the long delays here. Hopefully this will help more people use url_launcher successfully!

@CoreyCole
Copy link
Contributor Author

Happy to help out! 😄

@stuartmorgan-g stuartmorgan-g merged commit 957fb75 into flutter:master Jun 17, 2020
@stuartmorgan-g
Copy link
Contributor

The new README is live 🙂

agent3bood pushed a commit to agent3bood/flutter-plugins that referenced this pull request Jul 10, 2020
Add a note about encoding URLs passed to the url_launcher in the packages README.
jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
Add a note about encoding URLs passed to the url_launcher in the packages README.
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Add a note about encoding URLs passed to the url_launcher in the packages README.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants