Skip to content
Draft
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions packages/go_router/lib/src/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ class GoRoute extends RouteBase {
/// `/family/456` and etc. The parameter values are stored in [GoRouterState]
/// that are passed into [pageBuilder] and [builder].
///
/// A path parameter may optionally be constrained to a regular expression
/// by appending the expression in parentheses after the parameter name:
/// `:paramName(regex)`. The parameter only matches if the corresponding path
/// segment also matches the regular expression — segments that fail the
/// pattern fall through to other route candidates. For example,
/// `/users/:id(\d+)` matches `/users/42` but not `/users/alice`. The
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The example path contains a backslash (\d). In Dart, this requires using a raw string literal or escaping the backslash to avoid an 'Invalid escape sequence' error. Using the raw string prefix r in the documentation makes the example more accurate and easier for developers to use directly.

Suggested change
/// `/users/:id(\d+)` matches `/users/42` but not `/users/alice`. The
/// `r'/users/:id(\d+)'` matches `/users/42` but not `/users/alice`. The

/// expression must not introduce its own capturing groups; everything
/// between the parentheses is interpreted as a Dart [RegExp] body.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation of the path parser (_parameterRegExp in path_utils.dart) does not support un-escaped nested parentheses. Additionally, the internal escaping of characters like :, =, and ! prevents the use of advanced features such as non-capturing groups ((?:...)) or lookarounds. It is more accurate to state that the expression must not contain nested parentheses.

Suggested change
/// expression must not introduce its own capturing groups; everything
/// between the parentheses is interpreted as a Dart [RegExp] body.
/// expression must not contain nested parentheses; everything
/// between the parentheses is interpreted as a Dart [RegExp] body.

///
/// The query parameter are also capture during the route parsing and stored
/// in [GoRouterState].
///
Expand Down