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

Added test for Regex mapping for Servlet #7614

Merged
merged 1 commit into from Mar 22, 2022

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Feb 17, 2022

  • needed to open up ServletHandler to allow regex mappings

Signed-off-by: Greg Wilkins gregw@webtide.com

@gregw gregw added this to In progress in Jetty 10.0.9/11.0.9 (FROZEN) via automation Feb 17, 2022
@gregw gregw requested a review from joakime February 17, 2022 14:43
@joakime
Copy link
Contributor

joakime commented Mar 1, 2022

@gregw are you thinking of this as an alternate proposal over PR #5854 ?

@gregw
Copy link
Contributor Author

gregw commented Mar 2, 2022

@gregw are you thinking of this as an alternate proposal over PR #5854 ?

@joakime not specifically. I had observed recent client conversation about regex matching for servlets and knew that we had regex capability in our matcher. So I just wanted to test what would be involved to use that capability and it turns out that with a simple change to ServletHandler this is at least possible for some trivial cases. I had forgotten about #5854 and will have to look again to see what it is doing that this PR does not achieve (as it touches a lot more files).

So this PR really is just a thought bubble for consideration.... but it does indicate that a very trivial change with zero risk may enable some extra behaviors.

@joakime joakime added Enhancement Sponsored This issue affects a user with a commercial support agreement labels Mar 7, 2022
…xtHandler

+ needed to open up ServletHandler to allow regex mappings

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime joakime force-pushed the jetty-10.0.x-RegexServletHandler branch from 9af9a28 to 1dc3b93 Compare March 16, 2022 19:06
@joakime joakime marked this pull request as ready for review March 16, 2022 19:06
@joakime joakime self-assigned this Mar 16, 2022
@joakime joakime moved this from In progress to Review in progress in Jetty 10.0.9/11.0.9 (FROZEN) Mar 16, 2022
@joakime joakime requested review from sbordet March 16, 2022 22:06
Jetty 10.0.9/11.0.9 (FROZEN) automation moved this from Review in progress to Reviewer approved Mar 21, 2022
@joakime
Copy link
Contributor

joakime commented Mar 21, 2022

@gregw I updated this PR and cleaned up the testcases.
Since you cannot approve your own PR in github, I'm just going to ask.
Are you good with merging this? (I already approved it)

@gregw
Copy link
Contributor Author

gregw commented Mar 22, 2022

@joakime good to merge!

@gregw gregw merged commit cab9945 into jetty-10.0.x Mar 22, 2022
Jetty 10.0.9/11.0.9 (FROZEN) automation moved this from Reviewer approved to Done Mar 22, 2022
@gregw gregw deleted the jetty-10.0.x-RegexServletHandler branch March 22, 2022 08:48
@gregw
Copy link
Contributor Author

gregw commented Mar 22, 2022

@joakime I'm not sure tagging PRs with merge-12-needed is the right thing to do, as the PRs get closed. We need to tag the associated issue, which can be left open.

@joakime
Copy link
Contributor

joakime commented Mar 22, 2022

The PR contains the commits and eventual merge commit, those are what we want to ensure make it forward to jetty 12.

@gregw
Copy link
Contributor Author

gregw commented Apr 4, 2022

@joakime I'm back porting this to 9.4, which doesn't have the org.eclipse.jetty.http.pathmap.PathMappings#getMatch method. Instead it use the getPathMatch and getPathInfo methods.

Unfortunately these methods are not symmetric, and I'm wondering if you know why?
For example I would expect the following test to pass:

    @Test
    public void testMiddleSpecPaths()
    {
        RegexPathSpec spec = new RegexPathSpec("^/[Tt]est(/.*)?$");
        assertTrue(spec.matches("/test/info"));
        assertThat(spec.getPathMatch("/test/info"), equalTo("/test"));
        assertThat(spec.getPathInfo("/test/info"), equalTo("/info"));
    }

But it fails because the pathinfo returned is null??? I would expect either pathMatch==/test && pathInfo==/info or pathMatch==/test/info && pathInfo==null, but not pathMatch==/test && pathInfo==null, since that loses information.

If you look at the implementations, they are not symmetric: getPathMatch is conditional on matcher.groupCount() >= 1, whilst getPathInfo is conditional on PathSpecGroup.PREFIX_GLOB. Surely these should be the same test so both methods will split the path the same way?

Do you have any idea why it is like this? What might I break if I fix this?

@joakime
Copy link
Contributor

joakime commented Apr 4, 2022

The pattern ^/[Tt]est(/.*)?$ is interpreted as /*test/* which isn't a prefix pattern.
That's more of a middle pattern. The internal signature is detected as glllg which becomes PathSpecGroup.MIDDLE_GLOB, which cannot have a pathInfo.

If you want case insensitive, then we should perhaps open up regex flags to the new RegexPathSpec(String regex, int flags), so we can use new RegexPathSpec("^/test(/.*)?$", Pattern.CASE_INSENSITIVE) style of declaration?

@gregw
Copy link
Contributor Author

gregw commented Apr 4, 2022

@joakime I agree that it is a middle glob pattern. My issue is that the pathMatch and pathInfo are not implemented the same way. PathInfo tests for PREFIX, but pathMatch only cares that there are match groups.
In my PR I have made them both conditional on PREFIX_GLOB. I just want to know if there was a reason to implement them in a way that broke the invariant of path == contextPath + servletPath + pathInfo

joakime pushed a commit that referenced this pull request Oct 6, 2022
…xtHandler (#7614)

Added protected method to ServletHandler to allow other servlet mappings (eg regex) in embedded/extended usage

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Sponsored This issue affects a user with a commercial support agreement
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Allow overriding of url-pattern mapping in ServletContextHandler to allow for regex or uri-template matching
2 participants