Fix diffing of rendered text file attachments on Python 3.
Review Request #10709 — Created Sept. 10, 2019 and submitted
Rendered text file attachments (such as Markdown) are rendered as
Unicode, for output to the client. These were getting passed directly to
the differ, which itself takes byte strings. On Python 2, this all
worked out fine. On Python 3, this blew up pretty early, but in a way
that was hard to diagnose due any errors coming from subclasses just
being logged (with a massively-huge log message) and then the exception
ignored.The Markdown review UI specifically had another issue where we were
passing in a file handle containing byte strings, which was then getting
written back as byte strings but to aStringIO
expecting Unicode
strings. While the core issue lives in Djblets (and there's another
patch up that aims to fix this), it's better if we just read the file
content and convert to Unicode first, since the Markdown library doesn't
stream the file pointer anyway (it just grabs all the data at once).This change most of these issues by doing the following:
1) Ensures we're always passing the right string types around (both to
Markdown and the diff chunk generators).2) Switches the Markdown rendering call to
render_markdown()
, passing
it a Unicode string instead of a file handle.3) Adds new unit tests covering all this.
It does not address the overzealous exception sandboxing. That will be
taken care of separately.
Unit tests passed.
Verified I could view Markdown files in both rendered and source mode,
with diffs.
- Change Summary:
-
Fixed alignment issues.
- Commit:
-
5cc85332cd16234f1bffd6b25465f235591fb4787f669a165068abcfb27feaf516fadd3e90c43865
Checks run (2 succeeded)
- Change Summary:
-
Fixed the docs for
_get_diff_chunk_generator()
to includelist of bytes
as a valid type. - Commit:
-
7f669a165068abcfb27feaf516fadd3e90c43865218642f6a5bdce0aae708f6e9be1c5efd68ba922