Skip to content

UriComponentsBuilder loses the fragment when it consists of only a single character #36029

@aiai-guenz

Description

@aiai-guenz

Spring version: 7.0.1

Test class

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.core.SpringVersion;
import org.springframework.web.util.UriComponentsBuilder;

class UriComponentsBuilderTest {

  @Test
  void singleCharacterInFragment() {
    System.out.println("Spring version: " + SpringVersion.getVersion());
    var ucb = UriComponentsBuilder.fromUriString("https://example.com/path#1");
    assertThat(ucb.toUriString()).isEqualTo("https://example.com/path#1");
  }
}

Test output

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.UriComponentsBuilderTest
Spring version: 7.0.1
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.070 s <<< FAILURE! -- in com.example.demo.UriComponentsBuilderTest
[ERROR] com.example.demo.UriComponentsBuilderTest.singleCharacterInFragment -- Time elapsed: 0.064 s <<< FAILURE!
org.opentest4j.AssertionFailedError: 

expected: "https://example.com/path#1"
 but was: "https://example.com/path"
        at com.example.demo.UriComponentsBuilderTest.singleCharacterInFragment(UriComponentsBuilderTest.java:15)

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions