Skip to content

Commit 73e34e0

Browse files
authored
Fix characters encoding logic to provide valid json output (#1011)
1 parent 93bf680 commit 73e34e0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

core/src/main/python/wlsdeploy/json/json_translator.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ def _format_json_value(value):
248248

249249
def _escape_text(text):
250250
"""
251-
Escape the specified text for use in a double-quoted string.
252-
Escape embedded double quotes with a backslash.
251+
Escape the specified text for use in a double-quoted string to become valid json expression.
253252
:param text: the text to escape
254253
:return: the escaped text
255254
"""
@@ -259,4 +258,16 @@ def _escape_text(text):
259258
result = text.replace('\\', '\\\\')
260259
if '"' in text:
261260
result = text.replace('"', '\\"')
261+
if '\n' in text:
262+
result = text.replace("\n", "\\\\n")
263+
if '\b' in text:
264+
result = text.replace("\b", "\\\\b")
265+
if '\f' in text:
266+
result = text.replace("\f", "\\\\f")
267+
if '\r' in text:
268+
result = text.replace("\r", "\\\\r")
269+
if '\t' in text:
270+
result = text.replace("\t", "\\\\t")
271+
if '\/' in text:
272+
result = text.replace("\/", "\\\\/")
262273
return result

0 commit comments

Comments
 (0)