Skip to content

Commit 9d793a7

Browse files
authored
allow empty string key in YAML to support server logging properties (#540)
* allow empty string key in YAML in order to allow Logging properties to have things like "=Info"
1 parent c873913 commit 9d793a7

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

core/src/main/antlr4/oracle/weblogic/deploy/yaml/Yaml.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
33
* The Universal Permissive License (UPL), Version 1.0
44
*/
55
grammar Yaml;
@@ -176,6 +176,8 @@ FLOAT
176176

177177
NAME
178178
: ID_START ID_CONTINUE* WS?
179+
| '""' WS?
180+
| '\'\'' WS?
179181
| '\'' QUOTED_ID_START QUOTED_ID_CONTINUE* '\'' WS?
180182
| '"' QUOTED_ID_START QUOTED_ID_CONTINUE* '"' WS?
181183
;

core/src/main/python/wlsdeploy/yaml/yaml_translator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
Module to handle translating between Yaml files and Python dictionaries.
@@ -154,7 +154,7 @@ def _write_dictionary_to_yaml_file(self, dictionary, writer, indent=''):
154154
"""
155155
Do the actual heavy lifting of converting a dictionary and writing it to the file. This method is
156156
called recursively when a value of the dictionary entry is itself a dictionary.
157-
:param dictionary: the Python dictionarhy to converty
157+
:param dictionary: the Python dictionary to convert
158158
:param writer: the java.io.PrintWriter for the output file
159159
:param indent: the amount of indent to use (based on the level of recursion)
160160
:raises: IOException: if an error occurs while writing the output
@@ -254,12 +254,15 @@ def _close_streams(self, fos, writer):
254254

255255
def _quotify_string(self, text):
256256
"""
257-
Insert quotes around the string value if it contains Yaml special characters that require it.
257+
Insert quotes around the string value if it contains Yaml special characters that require it,
258+
or if the string is zero length.
258259
:param text: the input string
259260
:return: the quoted string, or the original string if no quoting was required
260261
"""
261262
if bool(re.search(self._requires_quotes_chars_regex, text)):
262263
result = '\'' + _quote_embedded_quotes(text) + '\''
264+
elif len(text) == 0:
265+
result = '\'\''
263266
else:
264267
result = _quote_embedded_quotes(text)
265268
return result

core/src/test/java/oracle/weblogic/deploy/yaml/YamlParserTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.yaml;
@@ -287,6 +287,24 @@ public void testEmptyObject() throws Exception {
287287
Assert.assertEquals("S2 Cluster not correct", EXPECTED_S2_CLUSTER, s2Cluster);
288288
}
289289

290+
@Test
291+
public void testEmptyStringKey() {
292+
Map<String, Object> topology = getMap(fileDict, "topology");
293+
Assert.assertNotNull("Failed to get topology from yaml", topology);
294+
295+
Map<String, Object> servers = getMap(topology, "Server");
296+
Assert.assertNotNull("Failed to get topology/Server from yaml", servers);
297+
298+
Map<String, Object> adminServer = getMap(servers, "AdminServer");
299+
Assert.assertNotNull("Failed to get topology/Server/AdminServer from yaml", adminServer);
300+
301+
Map<String, Object> log = getMap(adminServer, "Log");
302+
Assert.assertNotNull("Failed to get Log in AdminServer from yaml", adminServer);
303+
304+
Map<String, Object> properties = getMap(log, "LoggerSeverityProperties");
305+
Assert.assertEquals("Size of logging properties", 3, properties.size());
306+
Assert.assertTrue("Could not find empty string key in properties", properties.containsKey(""));
307+
}
290308
///////////////////////////////////////////////////////////////////////////
291309
// End of tests //
292310
///////////////////////////////////////////////////////////////////////////

core/src/test/resources/unit-test.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ domainInfo:
88

99
topology:
1010
Name: simple_domain
11+
'': nokey
1112
Cluster:
1213
mycluster:
1314
Server:
1415
AdminServer:
1516
ListenAddress: 127.0.0.1
1617
ListenPort: 7001
18+
Log:
19+
LoggerSeverityProperties:
20+
com.oracle.something: Debug
21+
# Adding test case for empty property key. Logging properties can have an empty key
22+
'': Info
23+
com.oracle.something.else: Debug
1724
s1:
1825
ListenAddress: 127.0.0.1
1926
ListenPort: 8001

0 commit comments

Comments
 (0)