Skip to content

Commit 8a72e55

Browse files
committed
Fix UriPathEncoder bug to improve performance
Fix `isAllowed` check and write test to ensure that additional object instances are not created unnecessarily. See gh-40615
1 parent d0ce4da commit 8a72e55

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/nio/file/UriPathEncoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private UriPathEncoder() {
3636
static String encode(String path) {
3737
byte[] bytes = path.getBytes(StandardCharsets.UTF_8);
3838
for (byte b : bytes) {
39-
if (isAllowed(b)) {
39+
if (!isAllowed(b)) {
4040
return encode(bytes);
4141
}
4242
}

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/nio/file/UriPathEncoderTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ void encodePath() {
3434
assertThat(UriPathEncoder.encode("/Z\u00fcrich")).isEqualTo("/Z%C3%BCrich");
3535
}
3636

37+
@Test
38+
void encodePathWhenNoEncodingIsRequiredReturnsSameInstance() {
39+
String path = "/foo/bar";
40+
assertThat(UriPathEncoder.encode(path)).isSameAs(path);
41+
}
42+
3743
}

0 commit comments

Comments
 (0)