Skip to content

[go_router] Support nested parentheses, groups, and lookaround assertions in path parameters - #12571

Merged
auto-submit[bot] merged 5 commits into
flutter:mainfrom
MaximeRougieux:fix/go-router-lookahead-path-params
Oct 30, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:mainfrom
MaximeRougieux:fix/go-router-lookahead-path-params

Conversation

@MaximeRougieux

@MaximeRougieux MaximeRougieux commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Example:
/tags/:slug((?!politics|economy)[^/]+) should match /tags/culture and not match /tags/politics, but the current behavior is that the internal parenthesis are unhandled and the pattern is then used literally :

  • /tags/flutter -> No match
  • /tags/politics -> No match
  • /tags/flutter((?!politics|economy))[^/]+) -> Match, slug="flutter"

Disclosure: I did the investigation and fix using AI, which i carefully reviewed and tried to improve as much as I could according to the AI contribution guidelines. I think it's still better to mention it

A few things to note:

  • Not a big fan of the "string-scanner" to find the closing parenthesis, but this is unachievable with a regex and needed for the fix to work as expected, and it's tested
  • You might be wondering why the _escapeGroup function is completely gone (and why it was there in the first place if we can just remove it like that). The AI retraces this to when the repository transitioned from using the path_to_regexp package to having the functions in the codebase. This package seems to be using positional group matching, whereas go_router relies on named group matching, so escaping characters like :,- or ! is unnecessary as they can't disrupt the matching from working as expected.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • 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 [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Aug 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors path parameter parsing in go_router by replacing the _parameterRegExp regular expression with a custom scanner (_pathParametersOf and _closingParenIndex) to correctly handle nested parentheses, escaped characters, and character classes within parameter constraints. It introduces a _PathParameter class and updates patternToRegExp and patternToPath to use the new scanner. Unit tests are added to verify the parsing of nested groups, group constructs, and parentheses in character classes. There are no review comments, and I have no feedback to provide.

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @MaximeRougieux thanks for contributing! One required step before we can move this forward: go_router uses the batched release process. Please add a pending changelog entry under packages/go_router/pending_changelogs/

@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

Hi @Piinks, I added the pending changelog, do you want me to squash it with the other commit or is it fine like that?

@Piinks

Piinks commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Hi @Piinks, I added the pending changelog, do you want me to squash it with the other commit or is it fine like that?

No it's fine. Everything gets squashed when merged

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this @MaximeRougieux!

I noticed a couple things to address:

  • The 4 tests added in path_utils_test.dart cover non-capturing groups (?: and lookaheads (?!, but none test an actual capturing group with alternation like (FOO|BAR) or the reproduction pattern from #117307 (r'/details/:id((FOO|BAR)[0-9a-zA-Z]{10})'). Please add a test for this in test/path_utils_test.dart.

  • The PR title mentions "capturing groups like (?!, (?: and (?=", but (?: is explicitly non-capturing and (?!/(?= are zero-width lookaround assertions. Could you update the PR title to:
    [go_router] Support nested parentheses, groups, and lookaround assertions in path parameters

    • In the description example /tags/:slug((?!politics|economy)), lookaheads are zero-width and do not consume characters, so without a trailing segment pattern like [^/]+, it won't match /tags/culture. Updating the example to /tags/:slug((?!politics|economy)[^/]+) will avoid confusion for reviewers and future archaeologists. :)
  • In packages/go_router/pending_changelogs/fix_lookahead_path_params.yaml, please adjust the entry to follow repo conventions (complete sentence ending in a period, accurate scope):

    changelog: |
      - Fixes path parameter regex parsing to support nested parentheses, grouping constructs, and lookahead assertions in GoRoute paths.
    version: patch

I think go_router_builder has a duplicate copy of path_utils.dart that has the same issue; would you like to follow up with an issue/PR to port this fix there as well?

@Piinks Piinks added the CICD Run CI/CD label Sep 3, 2026
@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

Hey @Piinks, thanks for the review!
Sure thing, I'll send the PR to go_router_builder after i've fixed everything and i'll reference it here 👌

@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

@Piinks everything should be good now, let me know if you need anything else on these PR

@Piinks Piinks added the CICD Run CI/CD label Sep 10, 2026

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM thank you!

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like there are some failing checks, can you take a look?

@MaximeRougieux
MaximeRougieux force-pushed the fix/go-router-lookahead-path-params branch from d695165 to 7ce8c1c Compare September 11, 2026 12:13
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 11, 2026
@MaximeRougieux

MaximeRougieux commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

It looks like there are some failing checks, can you take a look?

The logs are difficult to understand but it seems there was a class MockPlatform extends Mock implements Platform somewhere in the tool's code that triggered a compilation error during the job executions. I couldn't find it in the code so it could have been a temporary failure on main. I rebased just in case, could you start the CI/CD again please?

@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

@Piinks could you please relaunch the CI regarding this comment please?

@Piinks Piinks added the CICD Run CI/CD label Sep 24, 2026
@Piinks

Piinks commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Added!

@MaximeRougieux
MaximeRougieux force-pushed the fix/go-router-lookahead-path-params branch from 7ce8c1c to 131f1a6 Compare September 25, 2026 16:17
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 25, 2026
@MaximeRougieux

MaximeRougieux commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@Piinks it seems to have failed again on some unrelated ci change 😅 I rebased again, can you try reading the CI/CD label ? Third time will hopefully be the charm

@Piinks

Piinks commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@Piinks it seems to have failed again on some unrelated ci change 😅 I rebased again, can you try reading the CI/CD label ? Third time will hopefully be the charm

Have you tried running the tests locally?

@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

@Piinks it seems to have failed again on some unrelated ci change 😅 I rebased again, can you try reading the CI/CD label ? Third time will hopefully be the charm

Have you tried running the tests locally?

Yes, if you refer to go_router local tests, and to be clear they did not fail on this PR, the failing check was ci.yaml validation with a log i don't remember (and i can't find it in the check history).

It seemed like an unrelated failure, I assume rerunning the CI will work (unless it hits another issue of the same kind)

@MaximeRougieux
MaximeRougieux force-pushed the fix/go-router-lookahead-path-params branch from 131f1a6 to 8b8ff6e Compare September 28, 2026 13:56
@Piinks Piinks added the CICD Run CI/CD label Sep 28, 2026
@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

@Piinks it seems everything is finally passing here, thanks for your help!

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM thank you!

@Piinks
Piinks requested a review from elliette October 12, 2026 19:25
@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

Hi @elliette! Could you have a look on this when you have time please? Thanks! 😇

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! One small request - it looks like the documentation at

/// The regular expression is interpreted as a Dart [RegExp] pattern and must
/// not contain nested parentheses.
is now out-of-date - do you mind updating it to remove the line about not supporting nested parentheses? Thanks!

@MaximeRougieux
MaximeRougieux force-pushed the fix/go-router-lookahead-path-params branch from 8b8ff6e to 2a12b0b Compare October 26, 2026 14:37
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 26, 2026
@MaximeRougieux

Copy link
Copy Markdown
Contributor Author

Hi @elliette, thanks for the review!
I updated the doc comment and rebased the branch (no conflicts and the test suite passes locally), it should be good after another CI/CD run 🙂

@elliette elliette added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Oct 30, 2026
@auto-submit
auto-submit Bot merged commit c81561e into flutter:main Oct 30, 2026
14 checks passed
chunhtai pushed a commit to chunhtai/flutter that referenced this pull request Nov 2, 2026
flutter/packages@3742a4e...3f34a6f

2026-11-01 [email protected] Roll Flutter from
ee8b482 to fcfb4f2 (3 revisions) (flutter/packages#13520)
2026-10-31 [email protected] Roll Flutter from
5e805bf to ee8b482 (17 revisions) (flutter/packages#13512)
2026-10-30 [email protected] [VPAT] Describe the a11y_assessments
dialog for screen readers (flutter/packages#13462)
2026-10-30 [email protected] [go_router_builder] Allow `build` 5
(flutter/packages#13455)
2026-10-30 [email protected] [go_router]
Support nested parentheses, groups, and lookaround assertions in path
parameters (flutter/packages#12571)
2026-10-30 [email protected] [in_app_purchase_storekit] Add
SK2Transaction.currentEntitlements() (flutter/packages#13373)
2026-10-30 [email protected] [all]
Remove broken .claude/skills symlink (flutter/packages#13492)
2026-10-30 [email protected] Roll Flutter from
c091098 to 5e805bf (15 revisions) (flutter/packages#13504)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [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://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gmackall pushed a commit to gmackall/flutter that referenced this pull request Nov 3, 2026
flutter/packages@3742a4e...3f34a6f

2026-11-01 [email protected] Roll Flutter from
ee8b482 to fcfb4f2 (3 revisions) (flutter/packages#13520)
2026-10-31 [email protected] Roll Flutter from
5e805bf to ee8b482 (17 revisions) (flutter/packages#13512)
2026-10-30 [email protected] [VPAT] Describe the a11y_assessments
dialog for screen readers (flutter/packages#13462)
2026-10-30 [email protected] [go_router_builder] Allow `build` 5
(flutter/packages#13455)
2026-10-30 [email protected] [go_router]
Support nested parentheses, groups, and lookaround assertions in path
parameters (flutter/packages#12571)
2026-10-30 [email protected] [in_app_purchase_storekit] Add
SK2Transaction.currentEntitlements() (flutter/packages#13373)
2026-10-30 [email protected] [all]
Remove broken .claude/skills symlink (flutter/packages#13492)
2026-10-30 [email protected] Roll Flutter from
c091098 to 5e805bf (15 revisions) (flutter/packages#13504)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [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://issues.skia.org/issues/new?component=1389291&template=1850622

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 CICD Run CI/CD p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] path parameters regex can't use grouping

3 participants