Skip to content

spring:url tag does not correctly encode forward slash / in path variable. Should be calling encodePathSegment [SPR-11401] #16028

@spring-projects-issues

Description

@spring-projects-issues

daniel carter opened SPR-11401 and commented

The UrlTag advises that it will URL encode template URI variables

I have a path URL in my controller

@RequestMapping(value = "/circuit/{id}/view", method = RequestMethod.GET)

And the following in my jsp to call it:

<spring:url var="viewUrl" value="/circuit/{circuitId}/view" >
    <spring:param name="circuitId"  value="my/Id"/>
  </spring:url>

If for example id=my/Id then the tag writes out /circuit/my/Id/view

This obviously does not work as it fails to match the request mapping.

It should be URL encoding the path variable to write out /circuit/my%2FId/view

The problem is that / has a special meaning in paths, and thus needs to be escaped in path variables, but UrlTag.replaceUriTemplateParams calls UriUtils.encodePath(...) and ultimately at line 480 of HierarchicalUriComponents it decides that '/' does not need encoding

PATH {
		@Override
		public boolean isAllowed(int c) {
			return isPchar(c) || '/' == c;
		}
	},

Looks like UrlTag should be calling UriUtils.encodePathSegment(...) instead.


Affects: 3.2.5

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions