Skip to content

Path segment capturing {*…} not correctly expanded #1793

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

Closed
pcornelissen opened this issue May 29, 2022 · 4 comments
Closed

Path segment capturing {*…} not correctly expanded #1793

pcornelissen opened this issue May 29, 2022 · 4 comments
Assignees
Labels
in: core Core parts of the project type: bug
Milestone

Comments

@pcornelissen
Copy link

I have a controller with a mapping like this

@RequestMapping("/{tenantId}/{*categoryPath}")
public class PageByPathController {
    private final PageRepository pageRepository;
    private final PageResourceAssembler pageResourceAssembler;

    @GetMapping
    public Mono<String> getItem(@PathVariable UUID tenantId,
                                @PathVariable String categoryPath,
                                @RequestHeader(value = "Accept-Language", required = false) String language) {

When I try to create the links for this method, I tried to use something like this:

linkTo(methodOn(PageByPathController.class).getItem(entity.getTenantId(), entity.getPath(),null))

The resulting URLs path is then /2ffa5e8b-c141-4656-9dee-24d18a4f8ff0/{*categoryPath} So the categoryPath is not expanded.

@odrotbohm
Copy link
Member

Can you elaborate, what {*…} is supposed to mean? It's not a valid RFC6570 URI template variable.

@pcornelissen
Copy link
Author

Correct, the methodOn(...) stuff is using the webmvc URL mapping to create the URLs.
The {*foo} is a "catch-all" so a mapping like

/{myId}/{*path}
Would map to /456789/foo/bar/baz and path would be foo/bar/baz

In contrast to
/{myId}/{path} which would not match /456789/foo/bar/baz because path would only be foo and the /bar/baz suffix would not match

@odrotbohm odrotbohm added type: bug in: core Core parts of the project and removed process: waiting for feedback labels May 30, 2022
@odrotbohm odrotbohm added this to the 2.0 M4 milestone May 30, 2022
odrotbohm added a commit that referenced this issue May 30, 2022
We now properly handle path segment capture variables in URI mappings. Values handed into the dummy method invocations are expanded properly and a given null results in the composite segment template variable {/…*} being rendered to advertise the ability to add further segments.
odrotbohm added a commit that referenced this issue May 30, 2022
Introduced UriMapping to contain the original request mapping used on a controller method as well as a MappingVariables instance that captures all used variables of those mappings. These mappings and variables are not following URI template semantics but rather PathPattern. One example of this playing into the processing is the path segment capture syntax {*…}. This is roughly equivalent to URI template's composite path syntax {/…*}, which however looks different (as the leading slash is contained in the variable expression).

While the handling of those has been added in the commit before, we now introduce the proper abstractions that cause a couple of internal deprecations and binary-incompatible changes and we only want to impose them on implementors upgrading to 2.0. Also, this allows simplifying WebHandler which has accumulated quite a bit of logic already.
@odrotbohm
Copy link
Member

I've applied a fix to main that adds the general support to that. Working on that, it became clear that we should rather have better abstractions in place that allow us to handle the different places we need to teak to make this work in a single place.

You now should be able to expand values properly. Handing null as a value triggers the composite segment template variable {/…*} – i.e. proper URI template syntax – being added to the URI to advertise the ability to expand more path segments.

Backports to 1.5 and 1.4 coming in a second. Feel free to give the snapshots a try.

@pcornelissen
Copy link
Author

Thank you!

@odrotbohm odrotbohm changed the title WebFlux LinkTo builder does not work with eager path mapping (like {*foo}) Path segment capturing {*…} not correctly expanded May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

No branches or pull requests

2 participants