Skip to content

UriComponentsBuilder does not encode "+" properly [SPR-16718] #21259

Closed
@spring-projects-issues

Description

@spring-projects-issues

Joseph Mason opened SPR-16718 and commented

I noticed this issue after upgrading from Spring 4 to Spring 5. Basically, certain API calls we had been making with no issues before starting failing. Looking into it deeper, the issue is that the UriComponentsBuilder is not functioning the same as it was before. It's not clear to me if this is a bug or if there's a different way that this class needs to be used now.

This test passes when using Spring 4:

    @Test
    public void shouldEncodePlusSignInUrlProperly() throws Exception {
        //given
        UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance()
                .scheme("https")
                .host("test.com")
                .port(443);

        //when
        uriComponentsBuilder.queryParam("foo", "bar+");

        //then
        assertThat(uriComponentsBuilder.buildAndExpand().encode().toString()).isEqualTo("https://test.com:443?foo=bar%2B");
    }

But when using Spring 5, it will fail. Instead of this:

https://test.com:443?foo=bar%2B

it produces:

https://test.com:443?foo=bar+

Affects: 5.0 GA, 5.0.1, 5.0.2, 5.0.3, 5.0.4, 5.0.5

Issue Links:

0 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions