fix junitxml bin_xml_escape: supplementary plane characters incorrectly escaped#14484
fix junitxml bin_xml_escape: supplementary plane characters incorrectly escaped#14484EternalRights wants to merge 3 commits into
Conversation
for more information, see https://pre-commit.ci
| def test_bin_xml_escape_supplementary_plane() -> None: | ||
| assert bin_xml_escape(chr(0x1F600)) == chr(0x1F600) | ||
| assert bin_xml_escape("test_😀") == "test_😀" | ||
| assert bin_xml_escape("test_𠀀") == "test_𠀀" |
There was a problem hiding this comment.
What kinda whitespace is this
We may need to rename the function as we ought to avoid leaving likeness as is
There was a problem hiding this comment.
Good point, I'll fold the supplementary plane checks into the existing test and drop the separate function. Pushing a fix shortly.
…, drop separate function
bluetech
left a comment
There was a problem hiding this comment.
Thanks! Please see my comments.
| # Test some more invalid xml chars, the full range should be | ||
| # tested really but let's just test the edges of the ranges | ||
| # instead. | ||
| # XXX This only tests low unicode character points for now as |
There was a problem hiding this comment.
Do we need to adjust this comment?
| @@ -0,0 +1 @@ | |||
| Fixed ``bin_xml_escape`` in junitxml incorrectly escaping supplementary plane characters (U+10000 and above, including emoji) due to using ``\u`` instead of ``\U`` for the supplementary plane range in the ``illegal_xml_re`` regex. | |||
There was a problem hiding this comment.
Can you rewrite this changelog entry to be user-facing? A user doesn't know what bin_xml_escape is, and don't really care what was causing the bug (can click through to the issue if interested). The entry should describe the problem as the user might see it, in this case invalid escaping for high Unicode codepoints.
The
illegal_xml_reregex inbin_xml_escapewas using\u10000-\u10ffffto cover the supplementary plane range, but Python's\uescape only takes 4 hex digits. So\u10000was parsed as\u1000+0and\u10ffffas\u10ff+ff, meaning the entire supplementary plane (U+10000 to U+10FFFF) was missing from the "valid" character set.This caused all supplementary plane characters to be incorrectly escaped in JUnit XML output -- emoji, CJK Extension B-F, mathematical symbols, etc. For example
bin_xml_escape("test_😀")returned"test_#x1F600"instead of"test_😀".The fix: change
\u10000-\u10ffffto\U00010000-\U0010ffff(8-digit unicode escape).Also uncommented the supplementary plane code points in the existing
test_bin_xml_escapetest, and added a dedicatedtest_bin_xml_escape_supplementary_planetest with emoji, CJK Ext B, and musical symbol cases.Closes #14483