Skip to content

allow empty string key in YAML to support server logging properties #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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?
;
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/python/wlsdeploy/yaml/yaml_translator.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

: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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -287,6 +287,24 @@ public void testEmptyObject() throws Exception {
Assert.assertEquals("S2 Cluster not correct", EXPECTED_S2_CLUSTER, s2Cluster);
}

@Test
public void testEmptyStringKey() {
Map<String, Object> topology = getMap(fileDict, "topology");
Assert.assertNotNull("Failed to get topology from yaml", topology);

Map<String, Object> servers = getMap(topology, "Server");
Assert.assertNotNull("Failed to get topology/Server from yaml", servers);

Map<String, Object> adminServer = getMap(servers, "AdminServer");
Assert.assertNotNull("Failed to get topology/Server/AdminServer from yaml", adminServer);

Map<String, Object> log = getMap(adminServer, "Log");
Assert.assertNotNull("Failed to get Log in AdminServer from yaml", adminServer);

Map<String, Object> 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 //
///////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions core/src/test/resources/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down