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

Wrong reverse resolution #63

Open
joealbertvp opened this issue Jun 6, 2014 · 2 comments
Open

Wrong reverse resolution #63

joealbertvp opened this issue Jun 6, 2014 · 2 comments

Comments

@joealbertvp
Copy link

I'm using spring mvc 4 with thymeleaf,

i can configure thymeleaf using RouterModelAttribute in this way i have access in my view to the router with default name 'route'

My routes.conf content:

  •   /test/1 testController.foo
    

When i do ${route.reverse('testController.foo')} it give me the value of '/test/1/test/1' which is wrong url, i expect to /test/1 which is the value mapped to testController.foo.

I have looked to the code in the reverse method:

String path = route.path;
if( currentRequest != null) {
if(!currentRequest.servletPath.isEmpty() && !currentRequest.servletPath.equals("/")) {
String servletPath = currentRequest.servletPath;
path = (servletPath.startsWith("/") ? servletPath : "/" + servletPath) + path;
}

                        if(!currentRequest.contextPath.isEmpty() && !currentRequest.contextPath.equals("/")) {
                            String contextPath = currentRequest.contextPath; 
                            path = (contextPath.startsWith("/") ? contextPath : "/" + contextPath) + path;
                        }
                    }

** by removing this code the reverse method works as i should expect:
if(!currentRequest.servletPath.isEmpty() && !currentRequest.servletPath.equals("/")) {
String servletPath = currentRequest.servletPath;
path = (servletPath.startsWith("/") ? servletPath : "/" + servletPath) + path;

}

Could you confirm this issue?

@ssaavedra
Copy link

This happens when your servlet is configured as <url-pattern>/</url-pattern> instead of <url-pattern>/*</url-pattern> (notice the asterisk).

The code you mention is correct for the case when your url-pattern is more sophisticated, such as /app/place/*, where you would want to prepend the servlet.servletPath to your contextPath. However, the specification for mappings states:

  1. A string beginning with a ‘/’ character and ending with a ‘/*’ postfix is used for path mapping.
  2. A string beginning with a‘*.’ prefix is used as an extension mapping.
  3. A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
  4. All other strings are used for exact matches only.

Thus, a case for handing the 3rd rule there must be encoded. Scalatra seems to have the same problem currently (see scalatra/scalatra#392)

@bclozel
Copy link
Contributor

bclozel commented Feb 21, 2015

Could one of you submit a PR with a test and/or a fix for this?

castrinho8 pushed a commit to vacmatch/vacmatch that referenced this issue Dec 18, 2017
Problem is that springmvc router can't use "/" route and handle reverse
dependencies correctly.

See: resthub/springmvc-router#63
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

No branches or pull requests

3 participants