Skip to content

Conversation

ValentinVignal
Copy link
Contributor

Fixes flutter/flutter#130817
Relates to flutter/flutter#122713

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@ValentinVignal ValentinVignal requested a review from chunhtai as a code owner July 20, 2023 02:55
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Comment on lines 1 to 26
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'route.dart';

final RegExp _parameterRegExp = RegExp(r':(\w+)(\((?:\\.|[^\\()])+\))?');

/// Converts a [pattern] such as `/user/:id` into [RegExp].
///
/// The path parameters can be specified by prefixing them with `:`. The
/// `parameters` are used for storing path parameter names.
///
///
/// For example:
///
/// `pattern` = `/user/:id/book/:bookId`
///
/// The `parameters` would contain `['id', 'bookId']` as a result of calling
/// this method.
///
/// To extract the path parameter values from a [RegExpMatch], pass the
/// [RegExpMatch] into [extractPathParameters] with the `parameters` that are
/// used for generating the [RegExp].
RegExp patternToRegExp(String pattern, List<String> parameters) {
final StringBuffer buffer = StringBuffer('^');
Copy link
Contributor Author

@ValentinVignal ValentinVignal Jul 20, 2023

Choose a reason for hiding this comment

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

Comment on lines 90 to 104

/// Extracts arguments from the `match` and maps them by parameter name.
///
/// The [parameters] should originate from the call to [patternToRegExp] that
/// creates the [RegExp].
Map<String, String> extractPathParameters(
List<String> parameters, RegExpMatch match) {
return <String, String>{
for (int i = 0; i < parameters.length; ++i)
parameters[i]: match.namedGroup(parameters[i])!
};
}

/// Concatenates two paths.
///
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this commit (revamp: Remove unused methods) I'm only deleting methods that are not used

Comment on lines 15 to 48
/// `pattern` = `/user/:id/book/:bookId`
///
/// The `parameters` would contain `['id', 'bookId']` as a result of calling
/// this method.
///
/// To extract the path parameter values from a [RegExpMatch], pass the
/// [RegExpMatch] into [extractPathParameters] with the `parameters` that are
/// used for generating the [RegExp].
RegExp patternToRegExp(String pattern, List<String> parameters) {
final StringBuffer buffer = StringBuffer('^');
int start = 0;
for (final RegExpMatch match in _parameterRegExp.allMatches(pattern)) {
if (match.start > start) {
buffer.write(RegExp.escape(pattern.substring(start, match.start)));
}
final String name = match[1]!;
final String? optionalPattern = match[2];
final String regex = optionalPattern != null
? _escapeGroup(optionalPattern, name)
: '(?<$name>[^/]+)';
buffer.write(regex);
parameters.add(name);
start = match.end;
}

if (start < pattern.length) {
buffer.write(RegExp.escape(pattern.substring(start)));
}

if (!pattern.endsWith('/')) {
buffer.write(r'(?=/|$)');
}
return RegExp(buffer.toString(), caseSensitive: false);
}
Copy link
Contributor Author

@ValentinVignal ValentinVignal Jul 20, 2023

Choose a reason for hiding this comment

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

In this commit (refactor: Simplify path utils methods to only keep what is used),

I'm only deleting and simplifying patternToRegExp. We don't need to use the returned RegExp. So instead I'm returning the parameters (and I don't need the parameter parameters anymore)

@ValentinVignal
Copy link
Contributor Author

I believe this PR can have a no-test exemption. This is a revamp and the current tests should cover it already

@chunhtai chunhtai requested a review from hannah-hyj July 20, 2023 15:51
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

can you remove the path_to_regexp in script/configs/allowed_unpinned_deps.yaml, too?

@@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.2.2
version: 2.3.0
Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't a new feature, should probably update patch version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValentinVignal
Copy link
Contributor Author

can you remove the path_to_regexp in script/configs/allowed_unpinned_deps.yaml, too?

I removed it in ci: Remove path_to_regexp from allowed unpinned deps

@ValentinVignal ValentinVignal requested a review from chunhtai July 20, 2023 16:29
@chunhtai
Copy link
Contributor

It looks like the branch is outdated so the ci.yaml failed. can you rebase off latest main?

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@chunhtai chunhtai requested a review from stuartmorgan-g July 20, 2023 16:36
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@hannah-hyj hannah-hyj left a comment

Choose a reason for hiding this comment

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

LGTM

@Hixie
Copy link
Contributor

Hixie commented Jul 20, 2023

it's probably worth throwing in a few unit tests for the functions in packages/go_router_builder/lib/src/path_utils.dart, just so that the next person to refactor them can be confident they didn't break anything subtle about that code.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

As @Hixie stated, please add some tests and re-request my review once done

@ValentinVignal
Copy link
Contributor Author

tests: Add path_utils unit test

I added some unit tests in tests: Add path_utils unit test

@ValentinVignal ValentinVignal requested a review from chunhtai July 21, 2023 01:17
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 21, 2023
@auto-submit auto-submit bot merged commit 1af4d1a into flutter:main Jul 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 24, 2023
fluttermirroringbot pushed a commit to flutter/flutter that referenced this pull request Jul 24, 2023
flutter/packages@2266a76...8028caf

2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556)
2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552)
2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550)
2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547)
2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392)
2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548)
2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443)
2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543)
2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545)
2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544)
2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527)
2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies  (flutter/packages#4524)
2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Jul 31, 2023
flutter/packages@2266a76...8028caf

2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556)
2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552)
2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550)
2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547)
2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392)
2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548)
2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443)
2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543)
2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545)
2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544)
2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527)
2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies  (flutter/packages#4524)
2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
vashworth pushed a commit to vashworth/flutter that referenced this pull request Aug 2, 2023
flutter/packages@2266a76...8028caf

2023-07-24 [email protected] Roll Flutter from a8c8c55 to d7ed5dc (7 revisions) (flutter/packages#4556)
2023-07-23 [email protected] Roll Flutter from e8b397c to a8c8c55 (11 revisions) (flutter/packages#4552)
2023-07-22 [email protected] Roll Flutter from 9cfbf6b to e8b397c (12 revisions) (flutter/packages#4550)
2023-07-21 [email protected] [ci] Clean up except exclusion list (flutter/packages#4547)
2023-07-21 [email protected] [go_router] Replaces uri related properties in GoRouterState (flutter/packages#4392)
2023-07-21 [email protected] [webview_flutter_wkwebview] Updates pigeon version to `10.1.4` (flutter/packages#4548)
2023-07-21 [email protected] [pigeon] Adds package name to method channel. (flutter/packages#4443)
2023-07-21 [email protected] [ci] Migrate remaing unblocked repo checks to LUCI (flutter/packages#4543)
2023-07-21 [email protected] [go_router] Remove unused dependency (flutter/packages#4545)
2023-07-21 [email protected] Roll Flutter from d07e8ae to 9cfbf6b (58 revisions) (flutter/packages#4544)
2023-07-21 [email protected] Adding myself and Michele to AUTHORS (flutter/packages#4527)
2023-07-21 [email protected] [go_router_builder] Removes `path_to_regexp` from the dependencies  (flutter/packages#4524)
2023-07-21 [email protected] [google_maps_flutter_web] Adds options for gesture handling and tilt controls. (flutter/packages#4521)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: go_router_builder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[go_router_builder] Remove path_to_regexp
5 participants