Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2661a33ce4541f18eba8f4d00e59860e569c54dcb8ad83e138cfa120a987c9f1
Ticket: 0d61d3a2bb905178694d6cde8147039974600274
Tcl interprets two adjacent surrogate code points as a character encoded using UTF-16
User & Date: jan.nijtmans on 2021-03-08 09:09:11
Changes

  1. assignee changed to: "jan.nijtmans"
  2. icomment:
    Can you please change the example:
    
    <code><verbatim>
    set string \u1f91d
    </verbatim></code>
    into
    <code><verbatim>
    set string \U1f91d
    </verbatim></code>
    
    From this I'm assuming this bug report references 8.7, since 8.6 doesn't accept the \U?????-form yet for code points > U+FFFF.
    
    Tcl indeed interprets such escape sequences as you describe. It's a feature, not a bug. Internally, Tcl internally stores strings in two possible forms, one is [https://simonsapin.github.io/wtf-8/|WTF-8], the other one is UTF-16.
    Unicode allows use of such forms internally, as long as when communicating with the outside world it's translated into correct UTF-8. Since 8.6.10, Tcl does this correctly when it can (when it consists of valid surrogate-pairs) but allows WTF-8 forms to escape when they contain unpaired surrogates.
    
    I would like to deprecate such usage, see [https://core.tcl-lang.org/tips/doc/trunk/tip/573.md|TIP #573], but I don't think this would be accepted for 8.7. Maybe for 9.0, but - still - this TIP text is premature, fully open for discussion.
    
    For 8.x, yes it's too late, since \uD83E\uDD1D is already a valid (internal) representation for 🤝. It's the only portable way to do that in Tcl 8.6, in Tcl you can simply use the 🤝 character directly [https://core.tcl-lang.org/tips/doc/trunk/tip/587.md|TIP #587] or you can use the \U1F91D escape sequence.
    
    Can I close this ticket as "Fixed in 9.0"? If you find situations in which WTF-8 forms escape (like the two recent bugs Christian Werner reported), please file a bug report! I'm not claiming Tcl 8.6/8.7/9.0 is there yet ([https://core.tcl-lang.org/tips/doc/trunk/tip/587.md|TIP #575] is being voted on now), but it's getting better and better.
    
  3. login: "jan.nijtmans"
  4. mimetype: "text/x-fossil-wiki"