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:
@@ -145,14 +145,16 @@ public class ResourceController {
|
|||||||
// ensure InputStream will be closed to prevent file locks on Windows
|
// ensure InputStream will be closed to prevent file locks on Windows
|
||||||
try (InputStream is = resource.getInputStream()) {
|
try (InputStream is = resource.getInputStream()) {
|
||||||
String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
|
String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
|
||||||
String ext = StringUtils.getFilenameExtension(resource.getFilename())
|
String ext = StringUtils.getFilenameExtension(resource.getFilename());
|
||||||
.toLowerCase();
|
if (ext != null) {
|
||||||
|
ext = ext.toLowerCase();
|
||||||
|
}
|
||||||
Environment environment = this.environmentRepository.findOne(name, profile,
|
Environment environment = this.environmentRepository.findOne(name, profile,
|
||||||
label, false);
|
label, false);
|
||||||
if (resolvePlaceholders) {
|
if (resolvePlaceholders) {
|
||||||
text = resolvePlaceholders(prepareEnvironment(environment), text);
|
text = resolvePlaceholders(prepareEnvironment(environment), text);
|
||||||
}
|
}
|
||||||
if (encryptEnabled && plainTextEncryptEnabled) {
|
if (ext != null && encryptEnabled && plainTextEncryptEnabled) {
|
||||||
ResourceEncryptor re = this.resourceEncryptorMap.get(ext);
|
ResourceEncryptor re = this.resourceEncryptorMap.get(ext);
|
||||||
if (re == null) {
|
if (re == null) {
|
||||||
logger.warn("Cannot decrypt for extension " + ext);
|
logger.warn("Cannot decrypt for extension " + ext);
|
||||||
|
|||||||
@@ -175,6 +175,13 @@ public class ResourceControllerTests {
|
|||||||
assertThat(resource).isEqualToIgnoringNewLines("foo: dev_bar/spam");
|
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
|
@Test
|
||||||
public void resourceWithSlash() throws Exception {
|
public void resourceWithSlash() throws Exception {
|
||||||
this.environmentRepository.setSearchLocations("classpath:/test");
|
this.environmentRepository.setSearchLocations("classpath:/test");
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
foo: dev_bar
|
||||||
Reference in New Issue
Block a user