-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[url_launcher] docs: note about encoding URIs #2172
Conversation
There was a problem hiding this 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.
@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. |
To summarize here some later discussion in a bug, this is what I think a recommendation should look like for 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 |
Sorry this took me so long to get around to! Hopefully it looks good now. Happy holidays :) |
also trigger a rebuild because the previous cirrus build timed out while upgrading https://cirrus-ci.com/task/5460390574292992
also re-run the cirrus build it failed randomly again https://github.com/flutter/plugins/runs/413530777
@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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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. |
There was a problem hiding this comment.
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`: |
There was a problem hiding this comment.
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`: |
There was a problem hiding this comment.
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`: |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Don't worry about that part; once it's ready to go whoever is landing it can deal with the infrastructure flake. |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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. |
Done. I removed the version bump because this is only a documentation change as @stuartmorgan stated |
…mentation in the README
On second thought, it looks like the version has been bumped in the past for README changes. I bumped the version to |
There was a problem hiding this 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!
Happy to help out! 😄 |
The new README is live 🙂 |
Add a note about encoding URLs passed to the url_launcher in the packages README.
Add a note about encoding URLs passed to the url_launcher in the packages README.
Add a note about encoding URLs passed to the url_launcher in the packages README.
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.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?