Skip to content

Commit e4c07e8

Browse files
authored
Support launching a HTTPS URL (flutter#164720)
I setup a reverse proxy, but this piece of code only allows launching HTTP URLs. I'm submitting a patch to fix the error. See issue comment Dart-Code/Dart-Code#5322 (comment) for context. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent ec81e2e commit e4c07e8

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

packages/flutter_tools/lib/src/web/web_device.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ abstract class ChromiumDevice extends Device {
116116
// for the web initialization and server logic.
117117
String url;
118118
if (debuggingOptions.webLaunchUrl != null) {
119-
final pattern = RegExp(r'^((http)?:\/\/)[^\s]+');
120-
if (pattern.hasMatch(debuggingOptions.webLaunchUrl!)) {
119+
if (_isLaunchUrlValid(debuggingOptions.webLaunchUrl!)) {
121120
url = debuggingOptions.webLaunchUrl!;
122121
} else {
123122
throwToolExit('"${debuggingOptions.webLaunchUrl}" is not a valid HTTP URL.');
@@ -141,6 +140,11 @@ abstract class ChromiumDevice extends Device {
141140
return LaunchResult.succeeded(vmServiceUri: Uri.parse(url));
142141
}
143142

143+
bool _isLaunchUrlValid(String url) {
144+
final pattern = RegExp(r'^(https?:\/\/)[^\s]+');
145+
return pattern.hasMatch(url);
146+
}
147+
144148
@override
145149
Future<bool> stopApp(ApplicationPackage? app, {String? userIdentifier}) async {
146150
final Future<void>? future = _chrome?.close();

packages/flutter_tools/test/general.shard/web/devices_test.dart

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/build_info.dart';
1212
import 'package:flutter_tools/src/device.dart';
1313
import 'package:flutter_tools/src/web/chrome.dart';
1414
import 'package:flutter_tools/src/web/web_device.dart';
15+
import 'package:meta/meta.dart';
1516
import 'package:test/fake.dart';
1617

1718
import '../../src/common.dart';
@@ -31,16 +32,20 @@ void main() {
3132
expect(await webDevices.pollingGetDevices(), isEmpty);
3233
});
3334

35+
_FakeChromiumDevice getFakeChromiumDevice() {
36+
final launcher = TestChromiumLauncher(launcher: () => _OnceClosableChromium());
37+
38+
return _FakeChromiumDevice(
39+
chromiumLauncher: launcher,
40+
fileSystem: MemoryFileSystem.test(),
41+
logger: BufferLogger.test(),
42+
);
43+
}
44+
3445
testWithoutContext(
3546
'Successive calls of ChromiumDevice.stopApp() do not try to close chrome',
3647
() async {
37-
final launcher = TestChromiumLauncher(launcher: () => _OnceClosableChromium());
38-
39-
final chromiumDevice = _FakeChromiumDevice(
40-
chromiumLauncher: launcher,
41-
fileSystem: MemoryFileSystem.test(),
42-
logger: BufferLogger.test(),
43-
);
48+
final _FakeChromiumDevice chromiumDevice = getFakeChromiumDevice();
4449

4550
await chromiumDevice.startApp(
4651
null,
@@ -379,6 +384,41 @@ void main() {
379384

380385
expect((await macosWebDevices.pollingGetDevices()).whereType<MicrosoftEdgeDevice>(), isEmpty);
381386
});
387+
388+
@isTest
389+
void testWebLaunchUrl(String description, {required String url, required Matcher matcher}) {
390+
// ignore: unnecessary_parenthesis – Prevent IDEs from showing a run button.
391+
(testWithoutContext)(description, () async {
392+
final _FakeChromiumDevice chromiumDevice = getFakeChromiumDevice();
393+
394+
await expectLater(
395+
() => chromiumDevice.startApp(
396+
null,
397+
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, webLaunchUrl: url),
398+
platformArgs: <String, Object?>{'uri': url},
399+
),
400+
matcher,
401+
);
402+
});
403+
}
404+
405+
testWebLaunchUrl(
406+
'HTTP web launch url is not invalid',
407+
url: 'http://localhost:3000',
408+
matcher: returnsNormally,
409+
);
410+
411+
testWebLaunchUrl(
412+
'HTTPS web launch url is not invalid',
413+
url: 'https://localhost:3000',
414+
matcher: returnsNormally,
415+
);
416+
417+
testWebLaunchUrl(
418+
'Non-HTTP web launch url scheme is invalid',
419+
url: 'file://path',
420+
matcher: throwsToolExit(message: '"file://path" is not a valid HTTP URL.'),
421+
);
382422
}
383423

384424
/// A test implementation of the [ChromiumLauncher] that launches a fixed instance.

0 commit comments

Comments
 (0)