Skip to content

Conversation

@andrewnicols
Copy link

@andrewnicols andrewnicols commented Dec 10, 2024

This is the 1.3 version of #292. Since this is a bug it should really be part of a 1.3.x release.

This commit is based on the v1.3.0 tag. Ideally this should be included in a v1.3.1 release to support those using the library who are not in an immediate position to upgrade.

===

When using a route which contains both an unlimited optional placeholder, and another optional placeholder afterwards, the incorrect values are collected.

For example, given the following route:

/go/to/[{location:.*}[/info/{subpage}]]

The following behaviour is currently observed:

  • route: /go/to/[{location:.*}[/info/{subpage}]]
  • url: /go/to/australia/perth/info/about
  • location: 'australia/perth/info/about'
  • subpage: ''

Note that the location contains /info/about and the subpage is empty.

This is inconsistent with the behaviour where an unlimited value is not used:

  • route: /go/to/[{location}[/info/{subpage}]]
  • url: /go/to/australia/info/about
  • location: 'australia'
  • subpage: 'about'

In the case of the unlimited optional path, the expected behaviour is: The correct value would be:

  • route: /go/to/[{location:.*}[/info/{subpage}]]
  • url: /go/to/australia/perth/info/about
  • location: 'australia/perth'
  • subpage: 'about'

This commit change updates the route dispatcher to reverse the order of the routes when adding routes to the router, which brings the unlimited path placeholder format inline with limited path placeholders.

When using a route which contains both an unlimited optional
placeholder, and another optional placeholder afterwards, the incorrect
values are collected.

For example, given the following route:

```
/go/to/[{location:.*}[/info/{subpage}]]
```

The following behaviour is currently observed:

- route: `/go/to/[{location:.*}[/info/{subpage}]]`
- url: `/go/to/australia/perth/info/about`
- location: `'australia/perth/info/about'`
- subpage: `''`

Note that the `location` contains `/info/about` and the `subpage` is
empty.

This is inconsistent with the behaviour where an unlimited value is
_not_ used:

- route: `/go/to/[{location}[/info/{subpage}]]`
- url: `/go/to/australia/info/about`
- location: `'australia'`
- subpage: `'about'`

In the case of the unlimited optional path, the expected behaviour is:
The correct value would be:

- route: `/go/to/[{location:.*}[/info/{subpage}]]`
- url: `/go/to/australia/perth/info/about`
- location: `'australia/perth'`
- subpage: `'about'`

This commit change updates the route dispatcher to reverse the order of
the routes when adding routes to the router, which brings the unlimited
path placeholder format inline with limited path placeholders.

Signed-off-by: Andrew Nicols <andrew@nicols.co.uk>
andrewnicols added a commit to andrewnicols/moodle that referenced this pull request Dec 10, 2024
See the following upstream issues for further information:

- nikic/FastRoute#292
- nikic/FastRoute#293
@lcobucci lcobucci changed the base branch from master to v1.x December 10, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant