Skip to content
Tcl Source Code History Of Ticket 9f9c828fde97a4c8
Login

History Of Ticket 9f9c828fde97a4c8

Artifacts Associated With Ticket 9f9c828fde97a4c8

  1. Ticket change [0449cc999d] (rid 234852) by anonymous on 2024-11-05 15:51:41:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      When running the following code we get a corruption on the chinese characters string.
      
      set comment "测试包装"
      puts $comment
      set comment[string trim $comment]
      puts $comment
      
      Result in the following
      before trim
      测试包装
      
      after trim
      测试包�
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "ff32fef9c5c1dabc7c4e1934584fafc85a62e37c"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "44. UTF-8 Strings"
    15. title initialized to: "trim issue with chinese characters"
    16. type initialized to: "Bug"
  2. Ticket change [2c33aee64a] (rid 234853) by oehhar on 2024-11-05 17:00:31:

    1. icomment:
      That is weired !
      
      You mention Version 8.6.
      For me, on TCL 8.6.14, self compiled on Windows32 with MS-VC6 this does not happen. E.g., after the trim, the data is the same.
      And your data is on the Unicode base plane, so no surrogate issue.
      
      <verbatim>
      % set comment "测试包装"
      测试包装
      % string length $comment
      4
      % scan $comment %c%c%c%c c1 c2 c3 c4
      4
      % set c1
      27979
      % set c2
      35797
      % set c3
      21253
      % set c4
      35013
      % set comment2 [string trim $comment]
      测试包装
      % set comment2
      测试包装
      </verbatim>
      
      May you give more background, e.g. exact TCL version and platform, compiler,...
      
      Thank you,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  3. Ticket change [2e2caf0225] (rid 234854) by anonymous on 2024-11-06 10:00:15:

    1. icomment:
      Hi sorry for the missing info:
      
      Red Hat Enterprise Linux release 8.5 (Ootpa)
      
      echo 'puts $tcl_version;exit 0' | tclsh
      8.6
      
      It looks it is an issue with TCL using iso8859-1 (default encoding for TCL8.6)
      
      
      set comment "测试包装"
      set comment [encoding convertto utf-8 $comment]
      
      
      puts [binary encode hex $comment]
      
      puts $comment
      set comment [string trim $comment]
      puts [binary encode hex $comment]
      
      puts $comment
      
      
      without [encoding convertto utf-8 $comment] the string representation will not be UTF-8 on command line
      
      But running under Apache as CGI it is using UTF-8 as default, causing this issue.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  4. Add attachment "test_chinese.tcl" [0aa5555c4e] (rid 234855) by anonymous on 2024-11-06 10:01:08.

  5. Ticket change [736d574214] (rid 234856) by oehhar on 2024-11-06 11:19:43:

    1. icomment:
      Yes, console is always an issue.
      So, lets make the example use only 8859-1 codepage:
      
      <verbatim>
      set comment "\u6d4b\u8bd5\u5305\u88c5"
      set comment2 [string trim $comment]
      if {$comment eq $comment2} {puts identical}
      </verbatim>
      
      If this does not output "identical", it is the trim function, otherwise, it is something else.
      
      And please provide:
      <verbatim>
      info patchlevel
      </verbatim>
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  6. Ticket change [7fd80d63f4] (rid 234857) by oehhar on 2024-11-06 11:23:43:

    1. icomment:
      To examine your string without console influence, you may use:
      
      <verbatim>
      % lmap c [split $comment ""] {scan $c %c}
      27979 35797 21253 35013
      </verbatim>
      
      This prints the decimal unicode codepoints.
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  7. Ticket change [dae787ef94] (rid 234859) by anonymous on 2024-11-06 14:03:41:

    1. icomment:
      Using the following code:
      
      puts "Encoding: [encoding system]"
      set comment "测试包装"
      
      puts [lmap c [split $comment ""] {scan $c %c}]
      puts $comment
      set comment [string trim $comment]
      puts [lmap c [split $comment ""] {scan $c %c}]
      puts $comment
      
      
      Running on command line the output is this:
      ./test_chinese.tcl
      Encoding: utf-8
      27979 35797 21253 35013
      测试包装
      27979 35797 21253 35013
      测试包装
      
      
      Running from CGI webpage:
      
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <meta charset="UTF-8">
      </head>
      <body>
      Encoding: iso8859-1
      230 181 139 232 175 149 229 140 133 232 163 133
      测试包装
      230 181 139 232 175 149 229 140 133 232 163
      测试包�
      ...
      </body>
      </html>
      
      
      ########
      
      It's related to encoding handling, the file is saved as UTF-8 but going through Apache. I will check Apache documentation and will update after.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  8. Ticket change [0983da2413] (rid 234860) by oehhar on 2024-11-06 14:10:31:

    1. icomment:
      Yes, that explains the behaviour.
      
      Unicode 133 is "Next Line" which is stripped-off be the trim command.
      
      That is why it is missing...
      
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  9. Ticket change [084ebb513c] (rid 234874) by jan.nijtmans on 2024-11-07 16:14:59:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2460622.17708222"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Found [https://stackoverflow.com/questions/9322410/set-encoding-in-python-3-cgi-scripts|this]
      
      Excerpt:
      
      4) a simple solution is to pass the Apache process's LANG environment variable through to the CGI script using Apache's mod_env PassEnv command in the server or virtual host configuration: PassEnv LANG; on Debian/Ubuntu make sure that in /etc/apache2/envvars you have uncommented the line ". /etc/default/locale" so that Apache runs with the system default locale and not the C (Posix) locale (which is also ASCII encoding)
      
      Make sure line similar to LANG="en_US.UTF-8" is present in /etc/default/locale
      
      So, I think this ticket can be closed: It's not a bug in Tcl
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Invalid"
    8. status changed to: "Closed"