| Ticket UUID: | 5b5ba0aa0d0c78636f2fef90558e2b84c3e4bae4 | ||
| Title: | macJapanese encoding is incomplete | ||
| Type: | Bug | Created on: | 2021-11-15 21:01:14 |
| Submitter: | gingerbeardman | Assigned to: | jan.nijtmans |
| Subsystem: | - New Builtin Commands | Severity: | Minor |
| Priority: | 5 Medium | Last modified: | 2021-11-17 22:21:59 |
| Status: | Closed | Closed by: | gingerbeardman |
| Resolution: | Invalid | Closed on: | 2021-11-17 22:21:59 |
| Version: | 8.5.9 | ||
| Description: | ||||
It seems that the macJapan encoding is incomplete in that it does not deal with the full range of characters as outlined in the spec. https://unicode.org/Public/MAPPINGS/VENDORS/APPLE/JAPANESE.TXT Background: I am spitting out raw filename data from Japanese CD-ROMs (using hfsutils' hls command) and receive the following stream of bytes: 3A90 BB95 6991 CC8C B194 C53A (I list the byte streams so you can easily reproduce this data) these bytes should be encoded to: 3AE8 A3BD E593 81E4 BD93 E9A8 93E7 8988 3A0A (the correct UTF-8 representation is :製品体験版: the commas are part of the text) but using Tcl [encoding convertfrom macJapan] it is encoded to: 3AE8 A3BD E593 81C2 910C EFBD B1E7 8988 3A0A The problematic bytes in this example are: 91CC (should be mapped to 4F53, but Tcl maps to E4BD 93) 8CB1 (should be mapped to 9A13, but Tcl maps to E9A8 93) It's odd that they are encoded into three bytes? These characters are in the range covered by JIS X0208-1990, but please be aware I have not done any investigation to see how deep this problem goes. Finally, I see in https://core.tcl-lang.org/tcl/info/535705ffffffffff that encoding problems will generate errors in future, which is great! That would really help. | ||||
| User Comments: | ||||
jan.nijtmans added on 2021-11-16 08:30:39:
Thanks for your report. The "macJapan" encoding is defined here: https://opensource.apple.com/source/tcl/tcl-10/tcl/tools/encoding/macJapan.txt. I don't think we can simply change that to the definition you are pointing to. I would be possible to add "japanese" as new encoding, the same with other encodings in the https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ directory. Would that help you? Any others in this list you would like? gingerbeardman added on 2021-11-17 10:23:14:
Thanks for the link to Apple's Tcl encoding document, I was not aware of it. The mapping is the same as the one I quoted but the Tcl document has implementation details. It's good! No correction needed. So, I did some more investigation. My code operated normally over stdin, so in fact this issue was because I was not treating the input file as binary to the required degree. I was doing: set in [open $f rb] ...but that was not enough. I also required: fconfigure $in -translation binary ...to get everything working correctly. I'm too new to Tcl to understand why rb alone was not enough. All to say, I no longer think there is a bug. Sorry for the false alarm! I don't have a need for any further encodings, the existing set is good. jan.nijtmans added on 2021-11-17 10:31:11:
In that case, I'm closing this one. I already did an [c26e3294a8bbd267|experiment], adding the "japanese" encoding, but if no-one needs it it doesn't make sense to add more and more 'retro' encodings, just for fun ;-) Thanks for your report! gingerbeardman added on 2021-11-17 10:34:59:
In that case please leave the new Japanese encoding, i'm intrigued how it differs from macJapan and I'll do some testing as soon as I figure out how to get Tcl source with that change (I can build it, no problem). Thanks! jan.nijtmans added on 2021-11-17 11:04:20:
Then, just download the japanese.enc here, and drop it in your tcl_library/encodings directory. That should be enough to make the "japanese" encoding work in your environment gingerbeardman added on 2021-11-17 22:04:47:
You can see how new I am to Tcl: where would I find "tcl_library/encodings" on modern macOS? gingerbeardman added on 2021-11-17 22:21:59:
I figured it out, i was using macOS system Tcl which seems not able to be modified. So I installed Tcl 8.6 through macports, copied the enc file in and set the shebang of my script to run using this Tcl. Works! Cheers | ||||
