Tcl Source Code

View Ticket
Login
Ticket UUID: 6474fbd934378bb2a9d505f2799f9787a10a3f09
Title: Tcl 8.7a5: why utf-8 is different?
Type: Bug Created on: 2022-01-14 09:05:51
Submitter: petasis Assigned to: jan.nijtmans
Subsystem: 44. UTF-8 Strings Severity: Minor
Priority: 5 Medium Last modified: 2022-01-16 09:46:38
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2022-01-16 09:46:38
Version: 8.7a5
Description:
Hi all,

I observe a difference in converting strings to utf-8 between Tcl 8.6/8.7a1 and 8.7a5.

In Tcl 8.6 I get:

binary scan [encoding convertto utf-8 \uD800] H* hex; puts $hex
> efbfbd

which seems the correct utf-8 encoding.

However, in Tcl 8.7a5 I get:

binary scan [encoding convertto utf-8 \uD800] H* hex; puts $hex
> eda080

What is the reason for this difference? Shouldn't the utf-8 bytes be the same, no matter what internal representation for strings is used by Tcl?

I know that this is invalid input (and only half of a "character"), but in my view what tcl 8.6 returns makes much more sense, as there is a (very) limited usage. The behaviour in 8.7 returns a character, hiding the problem in the input...

George
User Comments:
jan.nijtmans added on 2022-01-14 22:39:45:

Proposed fix [c4a89ec75de1ded1|here].

This was - indeed - an early attempt to solve a problem in Tcl, which could cause Tcl to generate invalid UTF-8. Since then, a new idea to solve this arised: TIP #601. So I agree to revert this to the Tcl 8.6 behavior. Starting with Tcl 9.0, this situation should (IMHO) throw an exception (by default).