Skip to content

Commit df5b06d

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 3d8d7ff commit df5b06d

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
@@ -556,7 +556,7 @@ public InternalParser captureQuery() {
556556
}
557557

558558
public void captureFragmentIfNotEmpty() {
559-
if (this.index > this.componentIndex + 1) {
559+
if (this.index > this.componentIndex) {
560560
this.fragment = captureComponent("fragment");
561561
}
562562
}

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
@@ -930,4 +930,13 @@ void expandPortAndPathWithoutSeparator(ParserType parserType) {
930930
assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test");
931931
}
932932

933+
@ParameterizedTest // gh-36029
934+
@EnumSource
935+
void singleCharFragment(ParserType parserType) {
936+
URI uri = UriComponentsBuilder
937+
.fromUriString("https://localhost/resource#a", parserType)
938+
.build().toUri();
939+
assertThat(uri.toString()).isEqualTo("https://localhost/resource#a");
940+
}
941+
933942
}

0 commit comments

Comments
 (0)