views:

158

answers:

1

I recently upgraded my app from Spring 2.5.6 to Spring 3.0.0. A few days later, I noticed that some of my pages were no longer functional. The problem appears to be my UserContent.do controller.

UserContent.do is mapped using the SimpleUrlHandlerMapping mapping. It looks like this:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
 <props>
  <prop key="/*/UserContent.do">UserContentController</prop>
 </props>
</property>
</bean>

The problem is that I allow user-generated content in that middle directory, so those URLs could be anything:

http://mysite.com/foo/UserContent.do
http://mysite.com/bob/UserContent.do
http://mysite.com/foo%0a%0dbob/UserContent.do

It's that third case that is the problem. For some reason, it appears that "\r\n" no longer matches * in Spring 3. It seems like it still works in Spring 2.5.6.

I plan on no longer allowing users to enter newline characters into that spot. It was an oversight to begin with. However, I'd like those URLs to keep working for SEO reasons. Is there a way I can map a URL with a URL encoded newline in it somehow in Spring 3?

+2  A: 

It seems to be that the simplest workaround is to use /**/UserContent.do (it will also match /'s in the middle).

EDIT:

More elegant approach, doesn't match /'s: /{foo:(?s:.*)}/UserContent.do (declares a path variable with a custom regexp using {name:regexp} syntax and uses (?s:X) to turn the Pattern.DOTALL flag on)

axtavt
Whoa, SimpleUrlHandlerMapping supports regular expressions?? Is that documented anywhere?
CaptainAwesomePants
@Captain: Interesting question. It's documented that `SimpleUrlHandlerMapping` uses `AntPathMatcher`, and that `AntPathMatcher` can handle path variables. The fact that `AntPathMatcher` can handle custom regexps seems to be mentioned only in JIRA (http://jira.springframework.org/browse/SPR-5812, and they also suggested it as a workaround for some other issues)
axtavt
Either way, thanks very much!
CaptainAwesomePants