From a02b757720fa349aed1c711f24d7ba653d5bdb46 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Wed, 12 Feb 2020 15:24:29 -0600 Subject: [PATCH 1/4] allow empty string key in YAML in order to allow Logging properties to have things like "=Info" --- .../antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 | 2 ++ .../python/wlsdeploy/yaml/yaml_translator.py | 7 +++++-- .../weblogic/deploy/yaml/YamlParserTest.java | 18 ++++++++++++++++++ core/src/test/resources/unit-test.yaml | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 b/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 index 09bd3840c1..489f2e4ba2 100644 --- a/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 +++ b/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 @@ -176,6 +176,8 @@ FLOAT NAME : ID_START ID_CONTINUE* WS? + | '""' WS? + | '\'\'' WS? | '\'' QUOTED_ID_START QUOTED_ID_CONTINUE* '\'' WS? | '"' QUOTED_ID_START QUOTED_ID_CONTINUE* '"' WS? ; diff --git a/core/src/main/python/wlsdeploy/yaml/yaml_translator.py b/core/src/main/python/wlsdeploy/yaml/yaml_translator.py index 76c85753d2..ca8e0497f1 100644 --- a/core/src/main/python/wlsdeploy/yaml/yaml_translator.py +++ b/core/src/main/python/wlsdeploy/yaml/yaml_translator.py @@ -154,7 +154,7 @@ def _write_dictionary_to_yaml_file(self, dictionary, writer, indent=''): """ Do the actual heavy lifting of converting a dictionary and writing it to the file. This method is called recursively when a value of the dictionary entry is itself a dictionary. - :param dictionary: the Python dictionarhy to converty + :param dictionary: the Python dictionary to convert :param writer: the java.io.PrintWriter for the output file :param indent: the amount of indent to use (based on the level of recursion) :raises: IOException: if an error occurs while writing the output @@ -254,12 +254,15 @@ def _close_streams(self, fos, writer): def _quotify_string(self, text): """ - Insert quotes around the string value if it contains Yaml special characters that require it. + Insert quotes around the string value if it contains Yaml special characters that require it, + or if the string is zero length. :param text: the input string :return: the quoted string, or the original string if no quoting was required """ if bool(re.search(self._requires_quotes_chars_regex, text)): result = '\'' + _quote_embedded_quotes(text) + '\'' + elif len(text) == 0: + result = '\'\'' else: result = _quote_embedded_quotes(text) return result diff --git a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java index 40942ba689..29e2595445 100644 --- a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java @@ -287,6 +287,24 @@ public void testEmptyObject() throws Exception { Assert.assertEquals("S2 Cluster not correct", EXPECTED_S2_CLUSTER, s2Cluster); } + @Test + public void testEmptyStringKey() { + Map topology = getMap(fileDict, "topology"); + Assert.assertNotNull("Failed to get topology from yaml", topology); + + Map servers = getMap(topology, "Server"); + Assert.assertNotNull("Failed to get topology/Server from yaml", servers); + + Map adminServer = getMap(servers, "AdminServer"); + Assert.assertNotNull("Failed to get topology/Server/AdminServer from yaml", adminServer); + + Map log = getMap(adminServer, "Log"); + Assert.assertNotNull("Failed to get Log in AdminServer from yaml", adminServer); + + Map properties = getMap(log, "LoggerSeverityProperties"); + Assert.assertEquals("Size of logging properties", 3, properties.size()); + Assert.assertTrue("Could not find empty string key in properties", properties.containsKey("")); + } /////////////////////////////////////////////////////////////////////////// // End of tests // /////////////////////////////////////////////////////////////////////////// diff --git a/core/src/test/resources/unit-test.yaml b/core/src/test/resources/unit-test.yaml index a4c87aeaaa..e6ff7389a3 100644 --- a/core/src/test/resources/unit-test.yaml +++ b/core/src/test/resources/unit-test.yaml @@ -8,12 +8,19 @@ domainInfo: topology: Name: simple_domain + '': nokey Cluster: mycluster: Server: AdminServer: ListenAddress: 127.0.0.1 ListenPort: 7001 + Log: + LoggerSeverityProperties: + com.oracle.something: Debug + # Adding test case for empty property key. Logging properties can have an empty key + '': Info + com.oracle.something.else: Debug s1: ListenAddress: 127.0.0.1 ListenPort: 8001 From 485328a61916f65fe8354260168dc2a678dce9c4 Mon Sep 17 00:00:00 2001 From: Carolyn Rountree Date: Thu, 13 Feb 2020 13:03:44 -0600 Subject: [PATCH 2/4] update copyright --- core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 b/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 index 489f2e4ba2..1a66237a2f 100644 --- a/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 +++ b/core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. * The Universal Permissive License (UPL), Version 1.0 */ grammar Yaml; From 73f2f8563e98ce2e5d1e0eb3698d464a04716633 Mon Sep 17 00:00:00 2001 From: Carolyn Rountree Date: Thu, 13 Feb 2020 13:04:32 -0600 Subject: [PATCH 3/4] update copyright --- core/src/main/python/wlsdeploy/yaml/yaml_translator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/python/wlsdeploy/yaml/yaml_translator.py b/core/src/main/python/wlsdeploy/yaml/yaml_translator.py index ca8e0497f1..2f227db7cf 100644 --- a/core/src/main/python/wlsdeploy/yaml/yaml_translator.py +++ b/core/src/main/python/wlsdeploy/yaml/yaml_translator.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. Module to handle translating between Yaml files and Python dictionaries. From aab1afdddee2b9f83bf5216798fd89a7b8c2b0a3 Mon Sep 17 00:00:00 2001 From: Carolyn Rountree Date: Thu, 13 Feb 2020 13:05:25 -0600 Subject: [PATCH 4/4] Update YamlParserTest.java --- .../test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java index 29e2595445..791f08f2a9 100644 --- a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. */ package oracle.weblogic.deploy.yaml;