Jonny Borges
Committed by GitHub

Merge pull request #3067 from korutx/fix-parse-route

Enhance Getx Route Parsing for HTTP/S App Links Compatibility
@@ -267,17 +267,17 @@ class ParseRouteTree { @@ -267,17 +267,17 @@ class ParseRouteTree {
267 Map<String, String> _parseParams(String path, PathDecoded routePath) { 267 Map<String, String> _parseParams(String path, PathDecoded routePath) {
268 final params = <String, String>{}; 268 final params = <String, String>{};
269 var idx = path.indexOf('?'); 269 var idx = path.indexOf('?');
  270 + final uri = Uri.tryParse(path);
  271 + if (uri == null) return params;
270 if (idx > -1) { 272 if (idx > -1) {
271 - path = path.substring(0, idx);  
272 - final uri = Uri.tryParse(path);  
273 - if (uri != null) {  
274 - params.addAll(uri.queryParameters);  
275 - } 273 + params.addAll(uri.queryParameters);
  274 + }
  275 + var paramsMatch = routePath.regex.firstMatch(uri.path);
  276 + if (paramsMatch == null) {
  277 + return params;
276 } 278 }
277 - var paramsMatch = routePath.regex.firstMatch(path);  
278 -  
279 for (var i = 0; i < routePath.keys.length; i++) { 279 for (var i = 0; i < routePath.keys.length; i++) {
280 - var param = Uri.decodeQueryComponent(paramsMatch![i + 1]!); 280 + var param = Uri.decodeQueryComponent(paramsMatch[i + 1]!);
281 params[routePath.keys[i]!] = param; 281 params[routePath.keys[i]!] = param;
282 } 282 }
283 return params; 283 return params;
@@ -135,7 +135,8 @@ void main() { @@ -135,7 +135,8 @@ void main() {
135 GetPage(page: () => Container(), name: '/first/:name'), 135 GetPage(page: () => Container(), name: '/first/:name'),
136 GetPage(page: () => Container(), name: '/second/:id'), 136 GetPage(page: () => Container(), name: '/second/:id'),
137 GetPage(page: () => Container(), name: '/third'), 137 GetPage(page: () => Container(), name: '/third'),
138 - GetPage(page: () => Container(), name: '/last/:id/:name/profile') 138 + GetPage(page: () => Container(), name: '/last/:id/:name/profile'),
  139 + GetPage(page: () => Container(), name: '/first/second/:token')
139 ], 140 ],
140 )); 141 ));
141 142
@@ -168,6 +169,12 @@ void main() { @@ -168,6 +169,12 @@ void main() {
168 expect(Get.parameters['id'], '1234'); 169 expect(Get.parameters['id'], '1234');
169 expect(Get.parameters['name'], 'ana'); 170 expect(Get.parameters['name'], 'ana');
170 expect(Get.parameters['job'], 'dev'); 171 expect(Get.parameters['job'], 'dev');
  172 +
  173 + Get.toNamed(
  174 + 'https://www.example.com/first/second/fa9662f4-ec3f-11ee-a806-169a3915b383',
  175 + );
  176 + await tester.pumpAndSettle();
  177 + expect(Get.parameters['token'], 'fa9662f4-ec3f-11ee-a806-169a3915b383');
171 }, 178 },
172 ); 179 );
173 180