From 20d7d96a23ef78805d255678acc44e814c8181b6 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Tue, 20 Dec 2022 21:41:27 -0500 Subject: [PATCH 1/4] Fix - Incorrect URL after pop twice --- packages/go_router/lib/src/path_utils.dart | 4 +++ packages/go_router/test/go_router_test.dart | 35 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index d7a20ff22d53..b81dffa5dd87 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -77,6 +77,10 @@ String removePatternFromPath(String pattern, String path) { buffer.write(RegExp.escape(pattern.substring(start))); } + if (path.endsWith('/')) { + buffer.write('/'); + } + if (!pattern.endsWith('/')) { buffer.write(r'(?=/|$)'); } diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index 560a429d5082..a7c981e04f01 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -953,6 +953,41 @@ void main() { ]); }); + testWidgets('on pop twice', (WidgetTester tester) async { + final List routes = [ + GoRoute( + path: '/', + builder: (_, __) => const DummyScreen(), + routes: [ + GoRoute( + path: 'settings', + builder: (_, __) => const DummyScreen(), + routes: [ + GoRoute( + path: 'profile', + builder: (_, __) => const DummyScreen(), + ), + ]), + ]), + ]; + + final GoRouter router = await createRouter(routes, tester, + initialLocation: '/settings/profile'); + + log.clear(); + router.pop(); + router.pop(); + await tester.pumpAndSettle(); + expect(log, [ + isMethodCall('selectMultiEntryHistory', arguments: null), + isMethodCall('routeInformationUpdated', arguments: { + 'location': '/', + 'state': null, + 'replace': false + }), + ]); + }); + testWidgets('on pop with path parameters', (WidgetTester tester) async { final List routes = [ GoRoute( From 75050e6f7476439884126ab4b68e2a46c3fdb66b Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Tue, 20 Dec 2022 21:51:39 -0500 Subject: [PATCH 2/4] Add change log --- packages/go_router/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 075e950d611a..1ca2c72551c8 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.1 + +- Fixes incorrect URL when pops multiple times + ## 6.0.0 - **BREAKING CHANGE** From 47c99a86af3c8a5f7c3cfcaf0a0267458a410ca6 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Tue, 20 Dec 2022 22:01:07 -0500 Subject: [PATCH 3/4] []go_router] version bump to 6.0.1 --- packages/go_router/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index edcfd0a077ab..46982a9f932c 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -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: 6.0.0 +version: 6.0.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 From 9a56605c5081f464766394d50234a328a0ae809f Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Wed, 21 Dec 2022 06:55:21 -0500 Subject: [PATCH 4/4] Update regex pattern --- packages/go_router/lib/src/path_utils.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index b81dffa5dd87..9f5195730258 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -77,12 +77,8 @@ String removePatternFromPath(String pattern, String path) { buffer.write(RegExp.escape(pattern.substring(start))); } - if (path.endsWith('/')) { - buffer.write('/'); - } - if (!pattern.endsWith('/')) { - buffer.write(r'(?=/|$)'); + buffer.write(r'(\/)?(?=/|$)'); } buffer.write(r'$'); final RegExp regexp = RegExp(buffer.toString(), caseSensitive: false);