Skip to content

Build: solve problem with sanitized output #9257

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 3 commits into from
May 24, 2022
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
8 changes: 3 additions & 5 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def sanitize_output(self, output):
# https://code.djangoproject.com/ticket/28201
sanitized = sanitized.replace('\x00', '')
except (TypeError, AttributeError):
sanitized = None
sanitized = ""

# Chunk the output data to be less than ``DATA_UPLOAD_MAX_MEMORY_SIZE``
output_length = len(output) if output else 0
Expand Down Expand Up @@ -315,10 +315,8 @@ def run(self):
cmd_stdout, cmd_stderr = out
else:
cmd_stdout = out
# Docker returns None when there's no stderr/stdout
# so we need to convert that to a string.
self.output = self.sanitize_output(cmd_stdout or "")
self.error = self.sanitize_output(cmd_stderr or "")
self.output = self.sanitize_output(cmd_stdout)
self.error = self.sanitize_output(cmd_stderr)
cmd_ret = client.exec_inspect(exec_id=exec_cmd['Id'])
self.exit_code = cmd_ret['ExitCode']

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_doc_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_error_output(self):
cmd = BuildCommand(['/bin/bash', '-c', 'echo -n FOOBAR 1>&2'])
cmd.run()
self.assertEqual(cmd.output, 'FOOBAR')
self.assertIsNone(cmd.error)
self.assertEqual(cmd.error, "")

def test_sanitize_output(self):
cmd = BuildCommand(['/bin/bash', '-c', 'echo'])
Expand Down