Skip to content

Commit 940f826

Browse files
Fix PEM-encoded text trimming of file contents with Windows line endings
See gh-41540
1 parent f8fdc4a commit 940f826

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.nio.file.StandardOpenOption;
2626
import java.security.PrivateKey;
2727
import java.security.cert.X509Certificate;
28-
import java.util.Arrays;
2928
import java.util.List;
3029
import java.util.Objects;
3130
import java.util.regex.Pattern;
@@ -35,7 +34,6 @@
3534
import org.springframework.core.io.Resource;
3635
import org.springframework.util.Assert;
3736
import org.springframework.util.StreamUtils;
38-
import org.springframework.util.StringUtils;
3937

4038
/**
4139
* PEM encoded content that can provide {@link X509Certificate certificates} and
@@ -54,9 +52,7 @@ public final class PemContent {
5452
private final String text;
5553

5654
private PemContent(String text) {
57-
this.text = Arrays.stream(StringUtils.delimitedListToStringArray(text, "\n"))
58-
.map(String::trim)
59-
.collect(Collectors.joining("\n"));
55+
this.text = text.lines().map(String::trim).collect(Collectors.joining("\n"));
6056
}
6157

6258
/**

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/pem/PemContentTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void ofReturnsContent() {
211211
}
212212

213213
private static String contentFromClasspath(String path) throws IOException {
214-
return new ClassPathResource(path).getContentAsString(StandardCharsets.UTF_8);
214+
return new ClassPathResource(path).getContentAsString(StandardCharsets.UTF_8).indent(0).stripTrailing();
215215
}
216216

217217
}

0 commit comments

Comments
 (0)