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

a Uri Value is incorrectly extracted if it contains '.'. [SPR-6164] #10832

Closed
spring-issuemaster opened this Issue Sep 29, 2009 · 12 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Sep 29, 2009

Zhou Wu opened SPR-6164 and commented

Suppose we have the controller request mapping as the following

@RequestMapping(value = "/my/{vari}", method = RequestMethod.GET)
@ResponseBody
public String getVari(@PathVariable String vari) {
System.out.println("vari=" + vari);
return vari;
}

If a request such as "http://localhost/myapp/my/abc.mycontroller.com" is submitted, the actually value of 'vari' obtained by Spring API only returns 'abc.mycontroller'.

Further investigation turns out the issue is at line 564 in https://src.springframework.org/svn/spring-framework/tags/spring-framework-3.0.0.RC1/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java. The pattern generated by the line results in "{vari}.". With the 'pathMatcher' (the matcher used at line 565) object created by AntPathStringMatcher("{vari}.", "abc.mycontroller.com", map), the value of 'vari' will be 'abc.mycontroller' in the 'map' variable after executing line 566.


Affects: 3.0 M4, 3.0 RC1

Attachments:

Issue Links:

  • #10899 RESTful URLs with path variables containing dots are incorrectly mapped ("is duplicated by")
  • #14660 Spring eats @PathVariable part after last dot ("is duplicated by")
  • #19242 @PathVariable will cut off the last point ("is duplicated by")
  • #12288 Allow valid file extension paths for content negotiation to be specified
  • #10208 ReSTful URLs with content type extension do not work properly

Referenced from: commits 8292491, e24e768

2 votes, 11 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 29, 2009

Zhou Wu commented

The controller for reproducing the issue.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 14, 2009

Arjen Poutsma commented

This is an unfortunate side effect to the resolution of #10208. And if we would roll back the fix for that issue, people using file extensions will complain :).

There is a workaround, by explicitly configuring a DefaultAnnotationHandlerMapping in your servlet context and to disable the useDefaultSuffixPattern property, like so:

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
  <property name="useDefaultSuffixPattern" value="false"/>
</bean>

This will override the default DefaultAnnotationHandlerMapping that is created, and not map file extensions.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 14, 2009

Grzegorz Borkowski commented

I had similar problems: see my comment to #10307 (http://jira.springframework.org/browse/SPR-5636?focusedCommentId=44259&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_44259).
(At that time, we decided to use IDs in urls instead of domain names, in order to not have dots, because of this issue)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 19, 2009

Zhou Wu commented

Hi Arjen, the workaround provided here has side effect: uri '/my' and '/my/' won't return the same result. Usually one only maps '/my'; '/my/' should return the same result as '/my'.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 1, 2010

Praveen Krishnan commented

I am using spring-web 3.0.3-RELEASE and i guess it should be resolved. But when i invoke my rest url, the path variable i get is still removing the .com at the end.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 25, 2011

Shane Witbeck commented

I'm using 3.0.5.RELEASE and still have this issue. In my case I have an email address being passed as a PathVariable but the TLD is getting truncated. For example foo@bar.com gets truncated to foo@bar.

Can someone from SpringSource verify this is still an issue?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 1, 2011

Eldon Coutinho commented

I'm using 3.0.5 RELEASE too and still have this issue too. My case is the same as Shane Witbeck say. Even after apply the configuration that Arjen Poutsma did post, the problem still occurs. Please SpringSource guys, help us.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 21, 2011

Rossen Stoyanchev commented

The new RequestMappingHandlerMapping in Spring 3.1 now provides an option to disable pattern matching by suffix, which does not affect matching to URLs with a trailing slash as described #10307.

There is work planned for Spring 3.2, which will provide a better alternative to turning pattern matching off completely by checking against a list of configured suffix types. This is described in #13120.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 25, 2012

Rossen Stoyanchev commented

Related issue #12288 is now resolved providing a better solution for this issue. There should be no need to disable suffix pattern matching any more as long you have configured valid file extensions.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 31, 2012

Daniel Serodio commented

@Rossen, #12288 is for Spring 3.2, which isn't release yet. What is the suggested fix/workaround for Spring 3.1 users?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 15, 2013

Saurabh commented

It is pretty simple just add ":.+" with your parameter like below:

here username is e-mail id

@RequestMapping(value = "checkuser/{username:.+}" , method=RequestMethod.GET)
@ResponseBody
boolean getUserName(@PathVariable("username") String userName) {
	boolean isUserAvailable = userDao.checkAvailable(userName);
	return isUserAvailable;
}

I am passing value from URL like :
http://localhost:8081/user/checkuser/test@test.com

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 30, 2013

sandip commented

I am using version 3.2.4 of spring and still facing same issue , do i need to do some more configurations ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment