Skip to content
Tcl Source Code History Of Ticket b69e00ecf6
Login

History Of Ticket b69e00ecf6

Artifacts Associated With Ticket b69e00ecf6

  1. Ticket change [8df4e87db5] (rid 243011) by apnadkarni on 2025-07-16 06:40:21:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      Logging this bug as a reminder to revisit Tcl internal handling of invalid strings.
      
      As an example of the broader issue, invalid UTF-8 sequences raise an error on `encoding convertfrom` but not on `encoding convertto`.
      
      ```
      % encoding convertfrom utf-8  \xEF\xBF\x7F
      unexpected byte sequence starting at index 0: '\xEF'
      % binary encode hex [encoding convertto utf-8 [testbytestring \xEF\xBF\x7F]]
      c3afc2bf7f
      ```
      
      Both the above are actually UTF8->UTF8 conversions, the first converting from standard UTF-8 to Tcl's internal UTF-8 and the latter in the other direction.
      
      (The `testbytestring` command is part of tcltest and a means to get a specific byte sequence, including invalid utf8 as above, into a `Tcl_Obj.bytes` field. Essentially it emulates `Tcl_NewStringObj` behavior from script.)
      
      `convertfrom` behaves correctly, raising an error, as that UTF-8 sequence is invalid. `convertto` on the other hand, instead of being strict and raising an error, behaves as Tcl8 despite the default strict profile.
      
      In general this behavior seems to be by design as internally there are many places where Tcl converts invalid sequences without raising an error but instead either mapping to some character, either U+FFFD, or cp1252 equivalent or assuming iso8859-1 encoding (there is no consistency in this mapping either!).
      
      While this situation only occurs when invalid data is passed in via `Tcl_NewStringObj`, `Tcl_AppendToObj` etc., I feel Tcl should raise an error (if possible, since some functions do not have an error reporting mechanism other than panicing) when this is detected. In particular,
      
      - the encoding routines should definitely raise an error under the strict policy irrespective of `convertto` or `convertfrom`
      
      - when there is no possibility of raising an error because of the API, there should be a standard character mapping used, preferably U+FFFD as neither cp1252 or iso8859-1 make any logical sense.
      
      This is a reminder to revisit this rather thorny issue of handling invalid internal string values.
      
    5. is_private initialized to: "0"
    6. login: "apnadkarni"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
    9. resolution initialized to: "None"
    10. severity initialized to: "Important"
    11. status initialized to: "Open"
    12. submitter initialized to: "apnadkarni"
    13. subsystem initialized to: "- New Builtin Commands"
    14. title initialized to:
      Tcl does not raise an error even when it detects an invalid internal UTF-8 sequence
      
    15. type initialized to: "Bug"
  2. Ticket change [b63c7798df] (rid 243012) by apnadkarni on 2025-07-16 06:40:41:

    1. login: "apnadkarni"
    2. mimetype: "text/plain"
    3. subsystem changed to: "11. Conversions from String"