diff --git a/packages/flutter_tools/lib/src/commands/build_web.dart b/packages/flutter_tools/lib/src/commands/build_web.dart index cf3f92aee4..52e2410ffa 100644 --- a/packages/flutter_tools/lib/src/commands/build_web.dart +++ b/packages/flutter_tools/lib/src/commands/build_web.dart @@ -166,7 +166,10 @@ class BuildWebCommand extends BuildSubCommand { } final String? baseHref = stringArg('base-href'); 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()) { throwToolExit('Missing index.html.'); diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart index a9a1bc1839..073bc90dfb 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart @@ -355,6 +355,28 @@ void main() { ProcessManager: () => processManager, 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 runner = createTestCommandRunner(buildCommand); + + await expectLater( + runner.run([ + '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: { + Platform: () => fakePlatform, + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); } void setupFileSystemForEndToEndTest(FileSystem fileSystem) {