Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl 8.7a5: why utf-8 is different?

Closed / Fixed6474fbd934378bb2a9d505f2799f9787a10a3f09Created 5 years agoUpdated 5 years ago
Descriptionplain2022-01-14 09:05:51
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
Referenced by2
jan.nijtmanswiki2022-01-14 22:39:45

Proposed fix [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).

jan.nijtmans Closed ticket [6474fbd934]. [History diff]2022-01-16 09:46:38
Log in (anonymous is fine) to add a comment.