Skip to content

Commit d0ffef6

Browse files
uemanmiquelbeltran
andauthored
fix(share_plus): Another try at fixing url encoding (#238)
* Here we go again * bump versions Co-authored-by: Miquel Beltran <[email protected]>
1 parent 585846f commit d0ffef6

File tree

11 files changed

+52
-8
lines changed

11 files changed

+52
-8
lines changed

packages/share_plus_linux/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.3
2+
3+
- Hotfix on 2.0.2, improved solution.
4+
15
## 2.0.2
26

37
- Fixes: share URL is constructed incorrectly #235

packages/share_plus_linux/lib/share_plus_linux.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ class ShareLinux extends SharePlatform {
2020
'body': text,
2121
};
2222

23+
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
2324
final uri = Uri(
2425
scheme: 'mailto',
25-
queryParameters: queryParameters,
26+
query: queryParameters.entries
27+
.map((e) =>
28+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
29+
.join('&'),
2630
);
2731

2832
if (await canLaunch(uri.toString())) {

packages/share_plus_linux/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: share_plus_linux
22
description: Linux implementation of the share_plus plugin
3-
version: 2.0.2
3+
version: 2.0.3
44
homepage: https://plus.fluttercommunity.dev/
55
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
66

packages/share_plus_linux/test/share_plus_linux_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
44
import 'package:url_launcher_platform_interface/link.dart';
55

66
void main() {
7-
test('url encoding is correct', () async {
7+
test('url encoding is correct for &', () async {
88
final mock = MockUrlLauncherPlatform();
99
UrlLauncherPlatform.instance = mock;
1010

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

16+
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
17+
test('url encoding is correct for spaces', () async {
18+
final mock = MockUrlLauncherPlatform();
19+
UrlLauncherPlatform.instance = mock;
20+
21+
await ShareLinux().share('foo bar', subject: 'bar foo');
22+
23+
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
24+
});
25+
1626
test('throws when url_launcher can\'t launch uri', () async {
1727
final mock = MockUrlLauncherPlatform();
1828
mock.canLaunchMockValue = false;

packages/share_plus_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.4
2+
3+
- Hotfix on 2.0.3, improved solution.
4+
15
## 2.0.3
26

37
- Fix #235: share URL is constructed incorrectly

packages/share_plus_web/lib/share_plus_web.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ class SharePlusPlugin extends SharePlatform {
3535
'body': text,
3636
};
3737

38+
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
3839
final uri = Uri(
3940
scheme: 'mailto',
40-
queryParameters: queryParameters,
41+
query: queryParameters.entries
42+
.map((e) =>
43+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
44+
.join('&'),
4145
);
4246

4347
if (await canLaunch(uri.toString())) {

packages/share_plus_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: share_plus_web
22
description: Web platform implementation of share_plus
33
homepage: https://plus.fluttercommunity.dev/
44
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
5-
version: 2.0.3
5+
version: 2.0.4
66

77
flutter:
88
plugin:

packages/share_plus_windows/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.3
2+
3+
- Hotfix on 2.0.2, improved solution.
4+
15
## 2.0.2
26

37
- Fixes: share URL is constructed incorrectly #235

packages/share_plus_windows/lib/share_plus_windows.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ class ShareWindows extends SharePlatform {
2020
'body': text,
2121
};
2222

23+
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
2324
final uri = Uri(
2425
scheme: 'mailto',
25-
queryParameters: queryParameters,
26+
query: queryParameters.entries
27+
.map((e) =>
28+
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
29+
.join('&'),
2630
);
2731

2832
if (await canLaunch(uri.toString())) {

packages/share_plus_windows/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: share_plus_windows
22
description: Windows implementation of the share_plus plugin
3-
version: 2.0.2
3+
version: 2.0.3
44
homepage: https://plus.fluttercommunity.dev/
55
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
66

packages/share_plus_windows/test/share_plus_windows_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
44
import 'package:url_launcher_platform_interface/link.dart';
55

66
void main() {
7-
test('url encoding is correct', () async {
7+
test('url encoding is correct for &', () async {
88
final mock = MockUrlLauncherPlatform();
99
UrlLauncherPlatform.instance = mock;
1010

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

16+
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
17+
test('url encoding is correct for spaces', () async {
18+
final mock = MockUrlLauncherPlatform();
19+
UrlLauncherPlatform.instance = mock;
20+
21+
await ShareWindows().share('foo bar', subject: 'bar foo');
22+
23+
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
24+
});
25+
1626
test('throws when url_launcher can\'t launch uri', () async {
1727
final mock = MockUrlLauncherPlatform();
1828
mock.canLaunchMockValue = false;

0 commit comments

Comments
 (0)