Browse Source

Fix PEM-encoded text trimming of file contents with Windows line endings

See gh-41540
pull/42018/merge
Scott Frederick 1 year ago
parent
commit
940f82669d
  1. 6
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java
  2. 2
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/pem/PemContentTests.java

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

@ -25,7 +25,6 @@ import java.nio.file.Path; @@ -25,7 +25,6 @@ import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
@ -35,7 +34,6 @@ import org.springframework.boot.io.ApplicationResourceLoader; @@ -35,7 +34,6 @@ import org.springframework.boot.io.ApplicationResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
/**
* PEM encoded content that can provide {@link X509Certificate certificates} and
@ -54,9 +52,7 @@ public final class PemContent { @@ -54,9 +52,7 @@ public final class PemContent {
private final String text;
private PemContent(String text) {
this.text = Arrays.stream(StringUtils.delimitedListToStringArray(text, "\n"))
.map(String::trim)
.collect(Collectors.joining("\n"));
this.text = text.lines().map(String::trim).collect(Collectors.joining("\n"));
}
/**

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

@ -211,7 +211,7 @@ class PemContentTests { @@ -211,7 +211,7 @@ class PemContentTests {
}
private static String contentFromClasspath(String path) throws IOException {
return new ClassPathResource(path).getContentAsString(StandardCharsets.UTF_8);
return new ClassPathResource(path).getContentAsString(StandardCharsets.UTF_8).indent(0).stripTrailing();
}
}

Loading…
Cancel
Save