Fix issues with multi-byte encodings in content sections.
Review Request #11714 — Created July 10, 2021 and submitted
The original implementations of the reader and writer didn't properly
handle multi-byte encodings, such as UTF-16 or UTF-32 strings.The reason for this came down to newlines. We were looking for and
adding newlines based on their 8-bit representation, assuming that all
content would end in those, or that we could add them to the end of each
line while splitting. This didn't actually work, and would result in
failures in multi-byte encodings.A few things had to be done to address this:
Some design flaws in the text utilities, which made assumptions on
lengths, offsets, and the presence of newline characters, had to be
fixed.We no longer store our newline constants as byte strings, but rather
Unicode strings. They're then encoded as needed to ensure that
they're in a compatible format. BOMs are stripped from these, to
avoid further corruption of content.The order in which we encode, decode, and process strings for content
sections has changed a bit. We add on a missing newline before
encoding, rather than after. We encode or decode newlines at the same
time as the content strings.Unit tests were updated to check different multi-byte encodings for all
the content sections, making sure they are written and parsed correctly.
All unit tests pass on Python 2 and 3.
Summary | ID |
---|---|
13fdb6033d6fe51870fceda32efafbbc1e9fabe6 |
Description | From | Last Updated |
---|---|---|
E101 indentation contains mixed spaces and tabs |
reviewbot | |
W191 indentation contains tabs |
reviewbot | |
E131 continuation line unaligned for hanging indent |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
W191 indentation contains tabs |
reviewbot | |
E131 continuation line unaligned for hanging indent |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
W191 indentation contains tabs |
reviewbot | |
E131 continuation line unaligned for hanging indent |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
W191 indentation contains tabs |
reviewbot | |
E131 continuation line unaligned for hanging indent |
reviewbot | |
E101 indentation contains mixed spaces and tabs |
reviewbot | |
F821 undefined name 'line_endings' |
reviewbot | |
F821 undefined name 'newline' |
reviewbot | |
E501 line too long (80 > 79 characters) |
reviewbot | |
E501 line too long (81 > 79 characters) |
reviewbot | |
F821 undefined name 'newline' |
reviewbot | |
F821 undefined name 'line_endings' |
reviewbot |
- Change Summary:
-
Fixed tabs that snuck in from some copy/pastes while building strings for unit tests.
- Commits:
-
Summary ID 665a0e757004b20d03716a5743cef3e941575c8c f68b4e116f265909781f1fcca153f335955aaf09
- Change Summary:
-
Fixed some long lines and a dead line of code.
- Commits:
-
Summary ID f68b4e116f265909781f1fcca153f335955aaf09 01e00fd8de9311f367ea7d7580c756c1b1987319
Checks run (2 succeeded)
- Change Summary:
-
Fixed an over-zealous tab to spaces replacement in the unit tests. Switched affected test cases to use
\t
instead of a tab character. - Commits:
-
Summary ID 01e00fd8de9311f367ea7d7580c756c1b1987319 13fdb6033d6fe51870fceda32efafbbc1e9fabe6