Artifacts Associated With Ticket 9f9c828fde97a4c8
Ticket change [0449cc999d] (rid 234852) by anonymous on 2024-11-05 15:51:41:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- 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 测试包�
- foundin initialized to: "8.6"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "ff32fef9c5c1dabc7c4e1934584fafc85a62e37c"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "44. UTF-8 Strings"
- title initialized to: "trim issue with chinese characters"
- type initialized to: "Bug"
Ticket change [2c33aee64a] (rid 234853) by oehhar on 2024-11-05 17:00:31:
- 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
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [2e2caf0225] (rid 234854) by anonymous on 2024-11-06 10:00:15:
- 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.
- login: "anonymous"
- mimetype: "text/plain"
- icomment:
Add attachment "test_chinese.tcl" [0aa5555c4e] (rid 234855) by anonymous on 2024-11-06 10:01:08.
Ticket change [736d574214] (rid 234856) by oehhar on 2024-11-06 11:19:43:
- 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 - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [7fd80d63f4] (rid 234857) by oehhar on 2024-11-06 11:23:43:
- 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. - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [dae787ef94] (rid 234859) by anonymous on 2024-11-06 14:03:41:
- 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. - login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [0983da2413] (rid 234860) by oehhar on 2024-11-06 14:10:31:
- 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
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [084ebb513c] (rid 234874) by jan.nijtmans on 2024-11-07 16:14:59:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2460622.17708222"
- closer changed to: "jan.nijtmans"
- 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
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Closed"