From 20f085a1f20cfdc256f148243d7c0b0af9eb4e83 Mon Sep 17 00:00:00 2001 From: Jonn Smith Date: Mon, 9 Apr 2018 16:53:28 -0400 Subject: [PATCH] Fixed the properties issue: https://github.com/lviggiano/owner/issues/226 --- .../java/org/aeonbits/owner/ConfigURIFactory.java | 11 +++++++++-- .../java/org/aeonbits/owner/ConfigURIFactoryTest.java | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/owner/src/main/java/org/aeonbits/owner/ConfigURIFactory.java b/owner/src/main/java/org/aeonbits/owner/ConfigURIFactory.java index 3d50f84c..b7276db0 100644 --- a/owner/src/main/java/org/aeonbits/owner/ConfigURIFactory.java +++ b/owner/src/main/java/org/aeonbits/owner/ConfigURIFactory.java @@ -40,8 +40,15 @@ URI newURI(String spec) throws URISyntaxException { return null; return url.toURI(); } else if (fixed.startsWith(FILE_PROTOCOL)) { - String path = fixSpacesToPercentTwenty(fixed); - return new URI(path); + // This check fixes the case where an environment variable has been + // specified for the path to the config file, but that environment + // variable is blank / undefined. + if ( fixed.equals(FILE_PROTOCOL) ) { + return new URI(""); + } else { + String path = fixSpacesToPercentTwenty(fixed); + return new URI(path); + } } else { return new URI(fixed); } diff --git a/owner/src/test/java/org/aeonbits/owner/ConfigURIFactoryTest.java b/owner/src/test/java/org/aeonbits/owner/ConfigURIFactoryTest.java index 66871382..f1467c84 100644 --- a/owner/src/test/java/org/aeonbits/owner/ConfigURIFactoryTest.java +++ b/owner/src/test/java/org/aeonbits/owner/ConfigURIFactoryTest.java @@ -26,4 +26,11 @@ public void shouldReturnAnURI() throws URISyntaxException { URI uri = h.newURI("classpath:test.properties"); assertNotNull(uri); } + + @Test + public void shouldReturnAUriWithEmptyFilePath() throws URISyntaxException { + ConfigURIFactory h = new ConfigURIFactory(this.getClass().getClassLoader(), new VariablesExpander(new Properties())); + URI uri = h.newURI("file:"); + assertNotNull(uri); + } }