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

See gh-41540
This commit is contained in:
Scott Frederick 2024-08-21 15:33:21 -05:00
parent f8fdc4a63d
commit 940f82669d
2 changed files with 2 additions and 6 deletions

View File

@ -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;
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 {
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"));
}
/**

View File

@ -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();
}
}