Skip to content

Commit 175c9d3

Browse files
committed
Polish "Prevent stack overflow when writing Path"
See gh-44507
1 parent a69991b commit 175c9d3

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ else if (value instanceof WritableJson writableJson) {
115115
throw new UncheckedIOException(ex);
116116
}
117117
}
118-
// https://github.com/spring-projects/spring-boot/issues/44502
119118
else if (value instanceof Path p) {
120119
writeString(p.toString());
121120
}

Diff for: spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JsonValueWriterTests.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,14 @@ void endWhenNotStartedThrowsException() {
241241
.isThrownBy(() -> valueWriter.end(Series.ARRAY)));
242242
}
243243

244-
// https://github.com/spring-projects/spring-boot/issues/44502
245-
@Test
244+
@Test // gh-44502
246245
void writeJavaNioPathWhenSingleElementShouldBeSerializedAsString() {
247-
assertThat(doWrite((valueWriter) -> valueWriter.write(Path.of("overflow")))).isEqualTo(quoted("overflow"));
246+
assertThat(doWrite((valueWriter) -> valueWriter.write(Path.of("a")))).isEqualTo(quoted("a"));
248247
}
249248

250-
@Test
251-
void writeJavaNioPathShouldShouldBeSerializedAsString() {
252-
assertThat(doWrite((valueWriter) -> valueWriter.write(Path.of("stack/overflow/error"))))
253-
.isEqualTo(quoted("stack\\/overflow\\/error"));
249+
@Test // gh-44502
250+
void writeJavaNioPathShouldBeSerializedAsString() {
251+
assertThat(doWrite((valueWriter) -> valueWriter.write(Path.of("a/b/c")))).isEqualTo(quoted("a\\/b\\/c"));
254252
}
255253

256254
private <V> String write(V value) {

0 commit comments

Comments
 (0)