Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 17.1.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for go_router, please create a changelog entry in pending_changes

- Fixes `patternToPath` to throw `GoException` when a path parameter is missing instead of producing URLs containing the literal "null".

## 17.1.0

- Adds `TypedQueryParameter` annotation to override parameter names in `TypedGoRoute` constructors.
Expand Down
6 changes: 5 additions & 1 deletion packages/go_router/lib/src/path_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ String patternToPath(String pattern, Map<String, String> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 17.1.0
version: 17.1.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
14 changes: 14 additions & 0 deletions packages/go_router/test/path_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = <String, String>{'id': '123'};
expect(
() => patternToPath(pattern, incompleteParams),
throwsA(isA<GoException>().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);
Expand Down