From 5bc6504b235923a280f7e810422b86e8f784f3e2 Mon Sep 17 00:00:00 2001 From: Jhonathan Queiroz Date: Tue, 24 Feb 2026 16:14:02 -0300 Subject: [PATCH 1/2] Fix patternToPath to throw when path parameter is missing --- packages/go_router/lib/src/path_utils.dart | 6 +++++- .../fix_pattern_to_path_throws.yaml | 3 +++ packages/go_router/test/path_utils_test.dart | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/go_router/pending_changelogs/fix_pattern_to_path_throws.yaml diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index ed1ce7cc2015..e4e2b323651f 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -85,7 +85,11 @@ String patternToPath(String pattern, Map pathParameters) { buffer.write(pattern.substring(start, match.start)); } final String name = match[1]!; - buffer.write(pathParameters[name]); + final String? value = pathParameters[name]; + if (value == null) { + throw GoException('Missing path parameter: $name'); + } + buffer.write(value); start = match.end; } diff --git a/packages/go_router/pending_changelogs/fix_pattern_to_path_throws.yaml b/packages/go_router/pending_changelogs/fix_pattern_to_path_throws.yaml new file mode 100644 index 000000000000..fd0702968c65 --- /dev/null +++ b/packages/go_router/pending_changelogs/fix_pattern_to_path_throws.yaml @@ -0,0 +1,3 @@ +changelog: | + - Fixes `patternToPath` to throw `GoException` when a path parameter is missing instead of producing URLs containing the literal "null". +version: patch diff --git a/packages/go_router/test/path_utils_test.dart b/packages/go_router/test/path_utils_test.dart index 6dbf91102676..3bbbb13a632a 100644 --- a/packages/go_router/test/path_utils_test.dart +++ b/packages/go_router/test/path_utils_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; +import 'package:go_router/go_router.dart' show GoException; import 'package:go_router/src/path_utils.dart'; void main() { @@ -95,6 +96,19 @@ void main() { expect(url, restoredUrl); }); + test('patternToPath throws when path parameter is missing', () { + const pattern = '/user/:id/book/:bookId'; + final incompleteParams = {'id': '123'}; + expect( + () => patternToPath(pattern, incompleteParams), + throwsA(isA().having( + (GoException e) => e.message, + 'message', + contains('Missing path parameter: bookId'), + )), + ); + }); + test('concatenatePaths', () { void verify(String pathA, String pathB, String expected) { final String result = concatenatePaths(pathA, pathB); From 475c420dadaf9c9a008f6038b4136483715a089b Mon Sep 17 00:00:00 2001 From: "Jhonathan C. Queiroz" <74057391+jhonathanqz@users.noreply.github.com> Date: Fri, 6 Mar 2026 09:18:30 -0300 Subject: [PATCH 2/2] Update packages/go_router/lib/src/path_utils.dart Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/go_router/lib/src/path_utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index e4e2b323651f..04082994abd0 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -87,7 +87,7 @@ String patternToPath(String pattern, Map pathParameters) { final String name = match[1]!; final String? value = pathParameters[name]; if (value == null) { - throw GoException('Missing path parameter: $name'); + throw GoException('Missing path parameter: $name for pattern "$pattern"'); } buffer.write(value); start = match.end;