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..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; @@ -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..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. @@ -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..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; @@ -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