Skip to content

Commit 8c5f0f0

Browse files
authored
[url_launcher] Error handling when URL cannot be parsed with Uri.parse (flutter#4365)
1 parent 090e406 commit 8c5f0f0

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

packages/url_launcher/url_launcher/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.12
2+
3+
* Fixed an error where 'launch' method of url_launcher would cause an error if the provided URL was not valid by RFC 3986.
4+
15
## 6.0.11
26

37
* Update minimum Flutter SDK to 2.5 and iOS deployment target to 9.0.

packages/url_launcher/url_launcher/lib/url_launcher.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ Future<bool> launch(
7171
Brightness? statusBarBrightness,
7272
String? webOnlyWindowName,
7373
}) async {
74-
final Uri url = Uri.parse(urlString.trimLeft());
75-
final bool isWebURL = url.scheme == 'http' || url.scheme == 'https';
74+
final Uri? url = Uri.tryParse(urlString.trimLeft());
75+
final bool isWebURL =
76+
url != null && (url.scheme == 'http' || url.scheme == 'https');
77+
7678
if ((forceSafariVC == true || forceWebView == true) && !isWebURL) {
7779
throw PlatformException(
7880
code: 'NOT_A_WEB_SCHEME',

packages/url_launcher/url_launcher/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
33
web, phone, SMS, and email schemes.
44
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
6-
version: 6.0.11
6+
version: 6.0.12
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"

packages/url_launcher/url_launcher/test/url_launcher_test.dart

+36
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,42 @@ void main() {
281281
await launchResult;
282282
expect(binding.renderView.automaticSystemUiAdjustment, true);
283283
});
284+
285+
test('open non-parseable url', () async {
286+
mock
287+
..setLaunchExpectations(
288+
url:
289+
'rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1',
290+
useSafariVC: false,
291+
useWebView: false,
292+
enableJavaScript: false,
293+
enableDomStorage: false,
294+
universalLinksOnly: false,
295+
headers: <String, String>{},
296+
webOnlyWindowName: null,
297+
)
298+
..setResponse(true);
299+
expect(
300+
await launch(
301+
'rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1'),
302+
isTrue);
303+
});
304+
305+
test('cannot open non-parseable url with forceSafariVC: true', () async {
306+
expect(
307+
() async => await launch(
308+
'rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1',
309+
forceSafariVC: true),
310+
throwsA(isA<PlatformException>()));
311+
});
312+
313+
test('cannot open non-parseable url with forceWebView: true', () async {
314+
expect(
315+
() async => await launch(
316+
'rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1',
317+
forceWebView: true),
318+
throwsA(isA<PlatformException>()));
319+
});
284320
});
285321
}
286322

0 commit comments

Comments
 (0)