Skip to content

Commit 0279ef7

Browse files
committed
Do not Escape Data on Log Messages
1 parent 2a7efac commit 0279ef7

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

github_action_utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
CommandTypes = Literal[
1313
"add-mask",
1414
"debug",
15-
"endgroup",
1615
"error",
1716
"group",
1817
"notice",
@@ -35,19 +34,23 @@ def _print_command(
3534
command: CommandTypes,
3635
command_message: str,
3736
options_string: Union[str] = "",
37+
escape_message: bool = True,
3838
) -> None:
3939
"""
4040
Helper function to print GitHub action commands to the shell.
41+
Docs: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
4142
4243
:param command: command name from `CommandTypes`
4344
:param command_message: message string
4445
:returns: None
4546
"""
46-
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
47+
if escape_message:
48+
command_message = _escape_data(command_message)
49+
4750
echo_message = (
4851
f"{COMMAND_MARKER}{command} "
4952
f"{options_string or ''}"
50-
f"{COMMAND_MARKER}{_escape_data(command_message)}"
53+
f"{COMMAND_MARKER}{command_message}"
5154
)
5255

5356
print(echo_message)
@@ -148,7 +151,7 @@ def echo(message: Any) -> None:
148151
:param message: Any type of message e.g. string, number, list, dict
149152
:returns: None
150153
"""
151-
print(_escape_data(message))
154+
print(message)
152155

153156

154157
def debug(message: str) -> None:
@@ -161,10 +164,7 @@ def debug(message: str) -> None:
161164
:param message: message string
162165
:returns: None
163166
"""
164-
_print_command(
165-
"debug",
166-
message,
167-
)
167+
_print_command("debug", message, escape_message=False)
168168

169169

170170
def notice(
@@ -202,6 +202,7 @@ def notice(
202202
line=line,
203203
end_line=end_line,
204204
),
205+
escape_message=False,
205206
)
206207

207208

@@ -240,6 +241,7 @@ def warning(
240241
line=line,
241242
end_line=end_line,
242243
),
244+
escape_message=False,
243245
)
244246

245247

@@ -278,6 +280,7 @@ def error(
278280
line=line,
279281
end_line=end_line,
280282
),
283+
escape_message=False,
281284
)
282285

283286

@@ -325,7 +328,7 @@ def start_group(title: str) -> None:
325328
:param title: title of the group
326329
:returns: None
327330
"""
328-
_print_command("group", title)
331+
_print_command("group", title, escape_message=False)
329332

330333

331334
def end_group() -> None:
@@ -379,7 +382,7 @@ def begin_stop_commands(token: Union[str, None] = None) -> str:
379382
if not token:
380383
token = str(uuid.uuid1())
381384

382-
_print_command("stop-commands", token)
385+
_print_command("stop-commands", token, escape_message=False)
383386

384387
return token
385388

tests/test_github_action_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def test__build_options_string(input_kwargs: Any, expected: str) -> None:
121121
"test_input,expected",
122122
[
123123
("test", "test\n"),
124-
("test\n", "test%0A\n"),
125-
("%test", "%25test\n"),
126-
("\rtest", "%0Dtest\n"),
124+
("test\n", "test\n\n"),
125+
("%test", "%test\n"),
126+
("\rtest", "\rtest\n"),
127127
],
128128
)
129129
def test_echo(capfd: Any, test_input: str, expected: str) -> None:
@@ -136,9 +136,9 @@ def test_echo(capfd: Any, test_input: str, expected: str) -> None:
136136
"test_input,expected",
137137
[
138138
("test", "::debug ::test\n"),
139-
("test\n", "::debug ::test%0A\n"),
140-
("%test", "::debug ::%25test\n"),
141-
("\rtest", "::debug ::%0Dtest\n"),
139+
("test\n", "::debug ::test\n\n"),
140+
("%test", "::debug ::%test\n"),
141+
("\rtest", "::debug ::\rtest\n"),
142142
],
143143
)
144144
def test_debug(capfd: Any, test_input: str, expected: str) -> None:
@@ -289,9 +289,9 @@ def test_get_user_input() -> None:
289289
"test_input,expected",
290290
[
291291
("test", "::group ::test\n"),
292-
("test\n", "::group ::test%0A\n"),
293-
("%test", "::group ::%25test\n"),
294-
("\rtest", "::group ::%0Dtest\n"),
292+
("test\n", "::group ::test\n\n"),
293+
("%test", "::group ::%test\n"),
294+
("\rtest", "::group ::\rtest\n"),
295295
],
296296
)
297297
def test_start_group(capfd: Any, test_input: str, expected: str) -> None:

0 commit comments

Comments
 (0)