Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path support after unlimited optional placeholders #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewnicols
Copy link

@andrewnicols andrewnicols commented Dec 9, 2024

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.

@andrewnicols andrewnicols force-pushed the optionalNestedGlobWithFollowingFolder branch from d291392 to 37f2f19 Compare December 9, 2024 16:11
@andrewnicols
Copy link
Author

Note: 1.3.0 is also impacted by this bug.

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
@andrewnicols andrewnicols force-pushed the optionalNestedGlobWithFollowingFolder branch from 37f2f19 to 15eceef Compare December 11, 2024 00:38
@andrewnicols
Copy link
Author

Any chance of a review on this issue?

Thanks

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 andrewnicols force-pushed the optionalNestedGlobWithFollowingFolder branch from 15eceef to 33637cd Compare December 22, 2024 15:22
@andrewnicols
Copy link
Author

I believe I've solved all of the GHA failures.

@lcobucci
Copy link
Collaborator

lcobucci commented Jan 3, 2025

@andrewnicols I'll have a look soon.

The problem here is that this will affect the performance of the matching process. Also it isn't really a bug, as unbound parameters aren't officially supported - thus the lack of tests for it.

@bwoebi
Copy link
Contributor

bwoebi commented Jan 3, 2025

I don't think this needs a fix. The regex should be simply ungreedy, i.e. {location:.*?}.

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.

3 participants