-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Sanitize BuildCommand.output by removing NULL characters #4552
Conversation
PostgreSQL doesn't support NULL (\x00) characters on TextFields. Django 2.0 introduces a new validator that doesn't allow NULL characters to reach the database: https://code.djangoproject.com/ticket/28201 This commit just replaces the NULL characters of the stdout and stder from the command ran by '' (empty string) to avoid conflicts when saving them into the database.
I didn't find an easy way to test this. I wrote a test like this def test_null_output(self):
"""Include NULL (\x00) characters on command output."""
cmd = BuildCommand(['/bin/bash', '-c', 'echo -n H\0i'])
cmd.run()
self.assertEqual(cmd.output, 'Hi') but it fails with an exception like
|
hmm, what about wrapping the clean step in a function like |
@stsewd thanks for the suggestion! I added a method into the BuildCommand class, update a test to check the amount of calls to it when running a command, and another test to check that method in particular. What do you think? |
628af29
to
7ba297e
Compare
7ba297e
to
0939caf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
# Mock BuildCommand.sanitized_output just to count the amount of calls, | ||
# but use the original method to behaves as real | ||
original_sanitized_output = cmd.sanitize_output | ||
with patch('readthedocs.doc_builder.environments.BuildCommand.sanitize_output') as sanitize_output: # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't run the linter on tests files, so, it doesn't matter having a # noqa
comment p:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In #4552 I fixed this for LocalBuildEnvironment but I forget to do exactly the same for Docker. This is what this commit does.
) In #4552 I fixed this for LocalBuildEnvironment but I forget to do exactly the same for Docker. This is what this commit does.
PostgreSQL doesn't support NULL (\x00) characters on TextFields.
Django 2.0 introduces a new validator that doesn't allow NULL characters to reach the database:
https://code.djangoproject.com/ticket/28201
This commit just replaces the NULL characters of the stdout and stder from the command ran by '' (empty string) to avoid conflicts when saving them into the database.
Closes #3900