Browse Source

Fix RfcUriParser parsing for single char fragments

Prior to this commit, the `RfcUriParser` would ignore URI fragments if
their length is < 2. This commit fixes the length check to allow for
single char fragments when parsing URIs.

Fixes gh-36029
6.2.x
Brian Clozel 21 hours ago
parent
commit
91a0c28fa9
  1. 2
      spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java
  2. 9
      spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

2
spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java

@ -563,7 +563,7 @@ abstract class RfcUriParser {
} }
public void captureFragmentIfNotEmpty() { public void captureFragmentIfNotEmpty() {
if (this.index > this.componentIndex + 1) { if (this.index > this.componentIndex) {
this.fragment = captureComponent("fragment"); this.fragment = captureComponent("fragment");
} }
} }

9
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

@ -914,4 +914,13 @@ class UriComponentsBuilderTests {
assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test"); assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test");
} }
@ParameterizedTest // gh-36029
@EnumSource
void singleCharFragment(ParserType parserType) {
URI uri = UriComponentsBuilder
.fromUriString("https://localhost/resource#a", parserType)
.build().toUri();
assertThat(uri.toString()).isEqualTo("https://localhost/resource#a");
}
} }

Loading…
Cancel
Save