Skip to content

Commit b83dcf3

Browse files
author
Matthias Koeppe
committed
src/sage/doctest/forker.py: Use urllib.parse.quote for github annotations
1 parent ce3b849 commit b83dcf3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/sage/doctest/forker.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,16 +1248,21 @@ def _failure_header(self, test, example, message='Failed example:'):
12481248
out.append(message)
12491249
elif self.options.format == 'github':
12501250
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions
1251+
from urllib.parse import quote
1252+
1253+
def q(string):
1254+
return quote(string, safe=' /,"\'')
1255+
12511256
if message.startswith('Warning: '):
1252-
command = f'::warning title={message}'
1257+
command = f'::warning title={q(message)}'
12531258
message = message[len('Warning: '):]
12541259
elif self.baseline.get('failed', False):
1255-
command = f'::notice title={message}'
1260+
command = f'::notice title={q(message)}'
12561261
message += ' [failed in baseline]'
12571262
else:
1258-
command = f'::error title={message}'
1263+
command = f'::error title={q(message)}'
12591264
if extra := getattr(example, 'extra', None):
1260-
message += f': {extra}'
1265+
message += f': {q(extra)}'
12611266
if test.filename:
12621267
command += f',file={test.filename}'
12631268
if test.lineno is not None and example.lineno is not None:
@@ -1266,7 +1271,7 @@ def _failure_header(self, test, example, message='Failed example:'):
12661271
lineno = None
12671272
else:
12681273
command += f',line={example.lineno + 1}'
1269-
command += f'::{message}'
1274+
command += f'::{q(message)}'
12701275
out.append(command)
12711276
else:
12721277
raise ValueError(f'unknown format option: {self.options.format}')
@@ -1442,7 +1447,7 @@ def report_failure(self, out, test, example, got, globs):
14421447
"""
14431448
if not self.options.initial or self.no_failure_yet:
14441449
self.no_failure_yet = False
1445-
example.extra = f'Got: {got!r}'
1450+
example.extra = f'Got: {got}'
14461451
returnval = doctest.DocTestRunner.report_failure(self, out, test, example, got)
14471452
if self.options.debug:
14481453
self._fakeout.stop_spoofing()
@@ -1594,7 +1599,7 @@ def report_unexpected_exception(self, out, test, example, exc_info):
15941599
if not self.options.initial or self.no_failure_yet:
15951600
self.no_failure_yet = False
15961601

1597-
example.extra = "Exception raised: " + repr("".join(traceback.format_exception(*exc_info)))
1602+
example.extra = "Exception raised:\n" + "".join(traceback.format_exception(*exc_info))
15981603
returnval = doctest.DocTestRunner.report_unexpected_exception(self, out, test, example, exc_info)
15991604
if self.options.debug:
16001605
self._fakeout.stop_spoofing()

0 commit comments

Comments
 (0)