Unverified Commit 31116770 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

improve error message when `--base-href` argument does not start with `/` (#142667)

Resolves https://github.com/flutter/flutter/issues/137700.

In particular, see [this comment from the thread](https://github.com/flutter/flutter/issues/137700#issuecomment-1920241979) to see exactly what this PR is addressing.
parent bdf2a748
...@@ -166,7 +166,10 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -166,7 +166,10 @@ class BuildWebCommand extends BuildSubCommand {
} }
final String? baseHref = stringArg('base-href'); final String? baseHref = stringArg('base-href');
if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) { if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) {
throwToolExit('base-href should start and end with /'); throwToolExit(
'Received a --base-href value of "$baseHref"\n'
'--base-href should start and end with /',
);
} }
if (!flutterProject.web.existsSync()) { if (!flutterProject.web.existsSync()) {
throwToolExit('Missing index.html.'); throwToolExit('Missing index.html.');
......
...@@ -355,6 +355,28 @@ void main() { ...@@ -355,6 +355,28 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)), BuildSystem: () => TestBuildSystem.all(BuildResult(success: true)),
}); });
testUsingContext('Rejects --base-href value that does not start with /', () async {
final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
await expectLater(
runner.run(<String>[
'build',
'web',
'--no-pub',
'--base-href=i_dont_start_with_a_forward_slash',
]),
throwsToolExit(
message: 'Received a --base-href value of "i_dont_start_with_a_forward_slash"\n'
'--base-href should start and end with /',
),
);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
} }
void setupFileSystemForEndToEndTest(FileSystem fileSystem) { void setupFileSystemForEndToEndTest(FileSystem fileSystem) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment