Skip to content

fix(share_plus): Another try at fixing url encoding #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/share_plus_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.3

- Hotfix on 2.0.2, improved solution.

## 2.0.2

- Fixes: share URL is constructed incorrectly #235
Expand Down
6 changes: 5 additions & 1 deletion packages/share_plus_linux/lib/share_plus_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class ShareLinux extends SharePlatform {
'body': text,
};

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
final uri = Uri(
scheme: 'mailto',
queryParameters: queryParameters,
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
.join('&'),
);

if (await canLaunch(uri.toString())) {
Expand Down
2 changes: 1 addition & 1 deletion packages/share_plus_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: share_plus_linux
description: Linux implementation of the share_plus plugin
version: 2.0.2
version: 2.0.3
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand Down
12 changes: 11 additions & 1 deletion packages/share_plus_linux/test/share_plus_linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
import 'package:url_launcher_platform_interface/link.dart';

void main() {
test('url encoding is correct', () async {
test('url encoding is correct for &', () async {
final mock = MockUrlLauncherPlatform();
UrlLauncherPlatform.instance = mock;

Expand All @@ -13,6 +13,16 @@ void main() {
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
});

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
test('url encoding is correct for spaces', () async {
final mock = MockUrlLauncherPlatform();
UrlLauncherPlatform.instance = mock;

await ShareLinux().share('foo bar', subject: 'bar foo');

expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
});

test('throws when url_launcher can\'t launch uri', () async {
final mock = MockUrlLauncherPlatform();
mock.canLaunchMockValue = false;
Expand Down
4 changes: 4 additions & 0 deletions packages/share_plus_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.4

- Hotfix on 2.0.3, improved solution.

## 2.0.3

- Fix #235: share URL is constructed incorrectly
Expand Down
6 changes: 5 additions & 1 deletion packages/share_plus_web/lib/share_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class SharePlusPlugin extends SharePlatform {
'body': text,
};

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
final uri = Uri(
scheme: 'mailto',
queryParameters: queryParameters,
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
.join('&'),
);

if (await canLaunch(uri.toString())) {
Expand Down
2 changes: 1 addition & 1 deletion packages/share_plus_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: share_plus_web
description: Web platform implementation of share_plus
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
version: 2.0.3
version: 2.0.4

flutter:
plugin:
Expand Down
4 changes: 4 additions & 0 deletions packages/share_plus_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.3

- Hotfix on 2.0.2, improved solution.

## 2.0.2

- Fixes: share URL is constructed incorrectly #235
Expand Down
6 changes: 5 additions & 1 deletion packages/share_plus_windows/lib/share_plus_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class ShareWindows extends SharePlatform {
'body': text,
};

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
final uri = Uri(
scheme: 'mailto',
queryParameters: queryParameters,
query: queryParameters.entries
.map((e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
.join('&'),
);

if (await canLaunch(uri.toString())) {
Expand Down
2 changes: 1 addition & 1 deletion packages/share_plus_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: share_plus_windows
description: Windows implementation of the share_plus plugin
version: 2.0.2
version: 2.0.3
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand Down
12 changes: 11 additions & 1 deletion packages/share_plus_windows/test/share_plus_windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
import 'package:url_launcher_platform_interface/link.dart';

void main() {
test('url encoding is correct', () async {
test('url encoding is correct for &', () async {
final mock = MockUrlLauncherPlatform();
UrlLauncherPlatform.instance = mock;

Expand All @@ -13,6 +13,16 @@ void main() {
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
});

// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
test('url encoding is correct for spaces', () async {
final mock = MockUrlLauncherPlatform();
UrlLauncherPlatform.instance = mock;

await ShareWindows().share('foo bar', subject: 'bar foo');

expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
});

test('throws when url_launcher can\'t launch uri', () async {
final mock = MockUrlLauncherPlatform();
mock.canLaunchMockValue = false;
Expand Down