Skip to content

Commit 91a0c28

Browse files
committed
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
1 parent c0e8a36 commit 91a0c28

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public InternalParser captureQuery() {
563563
}
564564

565565
public void captureFragmentIfNotEmpty() {
566-
if (this.index > this.componentIndex + 1) {
566+
if (this.index > this.componentIndex) {
567567
this.fragment = captureComponent("fragment");
568568
}
569569
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,4 +914,13 @@ void expandPortAndPathWithoutSeparator(ParserType parserType) {
914914
assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test");
915915
}
916916

917+
@ParameterizedTest // gh-36029
918+
@EnumSource
919+
void singleCharFragment(ParserType parserType) {
920+
URI uri = UriComponentsBuilder
921+
.fromUriString("https://localhost/resource#a", parserType)
922+
.build().toUri();
923+
assertThat(uri.toString()).isEqualTo("https://localhost/resource#a");
924+
}
925+
917926
}

0 commit comments

Comments
 (0)