Repository navigation
🐛 fix(encode): write WHATWG bytes for meta charset - #2499
Conversation
42ee565 to
f84f9bc
Compare
Merging this PR will degrade performance by 2.1%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
With meta_charset=True the bytes came from Python's codec while the declaration names the WHATWG encoding, so text the declared encoding can represent was refused whenever the two disagree (251 big5, 8,822 euc-kr and 1 gb18030 code points). Encode with WHATWG encoders built as inverses of the decoders instead, and refuse only characters with no byte in the declared encoding, naming the character and its position. Fixes tox-dev#2461
f84f9bc to
6317153
Compare
encode(..., Html(meta_charset=True))wrote bytes from Python's codec while the<meta charset>names the WHATWG encoding. Where the two disagree, the read-back check from #2282 refused the document: 251 big5, 8,822 euc-kr and 1 gb18030 code points that the declared encoding can represent.The declared form now encodes with WHATWG encoders built as inverses of the decoders: single-byte, Big5, EUC-KR, GB18030 (two- and four-byte), Shift_JIS, EUC-JP (with JIS X 0212) and a stateful ISO-2022-JP. A character is refused only when the declared encoding has no byte for it, and the
ValueErrornames the character, its code point and its position. The read-back check is gone, since every byte written now decodes to the character it came from.The issue's script reports 0 refusals for all 12 labels after the change. An exhaustive pass over U+0080 to U+10FFFF finds no character that encodes and reads back as something else; gb18030 refuses 19 private-use code points that no WHATWG byte sequence decodes to. The plain
encodepath is unchanged: callgrind on encode-inner, encode-inner-indent, encode-inner-minify and parse-inner-encode moves by under 5 instructions per call.Fixes #2461