Fix mangled kana output for JIS encoding #9988
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For JIS encoding, hiragana and katakana can be input in multiple forms. One form uses JISX 0201 escape sequences. Another is called 'GR-invoked' kana.
In the context of ISO-2022 encoding, bytes with a zero bit in the MSB are called "GL" (or "graphics left") and those with the MSB set are called "GR" (or "graphics right"). Regarding the variants of ISO-2022-JP which are called "JIS7" and "JIS8", Wikipedia states:
"Other, older variants known as JIS7 and JIS8 build directly on the 7-bit and 8-bit encodings defined by JIS X 0201 and allow use of JIS X 0201 kana from G1 without escape sequences, using Shift Out and Shift In or setting the eighth bit (GR-invoked), respectively."
In harmony with this, we have always accepted bytes from 0xA3-0xDF and decoded them to the corresponding hiragana/katakana. However, at some point I accidentally broke output for these kana. You can see the problem in 3v4l.org by running this program:
The results are:
You can see that from 8.1.0 - 8.1.11, there was a missing escape sequence at the end. That was caused because the flush functions were not being called properly, and has already been fixed. However, this also shows that the output for 8.2rc1-rc3 is completely invalid. It is trying to output a JISX 0208 sequence, but with 0x00 as one of the JISX 0208 bytes, which is illegal.
Add the missing code which will make the new text conversion filters behave the same as the old ones when outputting hiragana/katakana in JIS encoding.
FYA @cmb69 @Girgias @nikic @kamil-tekiela