TAMAYA-340 Bugfix for regex "\\." vs literal "." String.replaceAll(String, String) takes a regex as its first argument, not a literal replaceable string. The result of this is that any single-character environment variable is converted to use the "_" key which has special significance to the system. Tests in the extensions repo include some that have a single character which this change should get working again. I've included a test in this repo for that case as well.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7352d6ae Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7352d6ae Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7352d6ae Branch: refs/heads/master Commit: 7352d6ae062224a0c72f7524f43a072f9464fbb6 Parents: c95acfd Author: William Lieurance <[email protected]> Authored: Sun Jun 10 04:20:12 2018 -0500 Committer: William Lieurance <[email protected]> Committed: Sun Jun 10 04:38:37 2018 -0500 ---------------------------------------------------------------------- .../spisupport/propertysource/EnvironmentPropertySource.java | 4 ++-- .../propertysource/EnvironmentPropertySourceTest.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7352d6ae/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java index ac01586..570f5d4 100644 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java @@ -203,11 +203,11 @@ public class EnvironmentPropertySource extends BasePropertySource { String value = getPropertiesProvider().getenv(effectiveKey); // Replace all . by _ (i.e. com_ACME_size) if(value==null){ - value = getPropertiesProvider().getenv(effectiveKey.replaceAll(".", "_")); + value = getPropertiesProvider().getenv(effectiveKey.replaceAll("\\.", "_")); } // Replace all . by _ and convert to upper case (i.e. COM_ACME_SIZE) if(value==null){ - value = getPropertiesProvider().getenv(effectiveKey.replaceAll(".", "_") + value = getPropertiesProvider().getenv(effectiveKey.replaceAll("\\.", "_") .toUpperCase()); } return PropertyValue.of(key, value, getName()); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7352d6ae/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java index 9fd3fa7..6f21320 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java @@ -97,6 +97,11 @@ public class EnvironmentPropertySourceTest { assertThat(envPropertySource.getName()).isEqualTo("environment-properties"); } + @Test + public void testSingleCharacterNull() { + assertThat(envPropertySource.get("a")).isNull(); + } + @Test public void testGet() throws Exception { for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
