Merge pull request #1559 from mohammedalics/fixesgh/20302

Add check if the file extension is null before calling the to toLowerCase() - Fixes gh-20302
This commit is contained in:
Ryan Baxter
2020-02-27 10:10:10 -05:00
committed by GitHub
3 changed files with 13 additions and 3 deletions

View File

@@ -145,14 +145,16 @@ public class ResourceController {
// ensure InputStream will be closed to prevent file locks on Windows
try (InputStream is = resource.getInputStream()) {
String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
String ext = StringUtils.getFilenameExtension(resource.getFilename())
.toLowerCase();
String ext = StringUtils.getFilenameExtension(resource.getFilename());
if (ext != null) {
ext = ext.toLowerCase();
}
Environment environment = this.environmentRepository.findOne(name, profile,
label, false);
if (resolvePlaceholders) {
text = resolvePlaceholders(prepareEnvironment(environment), text);
}
if (encryptEnabled && plainTextEncryptEnabled) {
if (ext != null && encryptEnabled && plainTextEncryptEnabled) {
ResourceEncryptor re = this.resourceEncryptorMap.get(ext);
if (re == null) {
logger.warn("Cannot decrypt for extension " + ext);

View File

@@ -175,6 +175,13 @@ public class ResourceControllerTests {
assertThat(resource).isEqualToIgnoringNewLines("foo: dev_bar/spam");
}
@Test
public void resourceWithoutFileExtension() throws Exception {
this.environmentRepository.setSearchLocations("classpath:/test");
String resource = this.controller.retrieve("foo", "bar", "dev", "foo", true);
assertThat(resource).isEqualToIgnoringNewLines("foo: dev_bar");
}
@Test
public void resourceWithSlash() throws Exception {
this.environmentRepository.setSearchLocations("classpath:/test");

View File

@@ -0,0 +1 @@
foo: dev_bar