Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-03-02
20:06 • Closed ticket [b3fbd9a6e0]: string trim generates invalid utf-8 for some codepoi... artifact: c5bbbde7bf user: jan.nijtmans
19:48
Fix [b3fbd9a6e0]: string trim generates invalid utf-8 for some codepoints check-in: 94529656ae user: jan.nijtmans tags: core-8-6-branch
2026-01-06
11:45 • Add attachment tclUtil.diff to ticket [b3fbd9a6e0] artifact: e2f1a78e88 user: chelmuth
07:18 • New ticket [b3fbd9a6e0] string trim generates invalid utf-8 for some codepoints<... artifact: afb3da897f user: chelmuth

string trim generates invalid utf-8 for some codepoints

Closed / Fixedb3fbd9a6e028dfa5c0138a461fdb5b4ae09ffebcCreated 331 days agoUpdated 275 days ago
Descriptionplain2026-01-06 07:18:10
The following code produces invalid UTF-8 strings and causes puts to abort.

set padded_unicode_22c5 " \U22c5 "
set trimmed_unicode_22c5 [string trim $padded_unicode_22c5]

puts "padded_unicode_22c5: '$padded_unicode_22c5'"
puts "trimmed_unicode_22c5: '$trimmed_unicode_22c5'"

The same happens for U+2020.

Most interestingly the characters are represented by UTF-8 sequences like follows.

U+22C5 0xE2 0x87 0x85
U+2020 0xE2 0x80 0xA0

The first sequence contains 0x85 and the second 0x80.
U+0085 (0xC2 0x85) is <Next Line> (NEL).
U+0080 (0xC2 0x80) is <Padding Character> (PAD).
Both should be trimmed I expect but are not in the string above (0xC2 is missing).

I also tested Tcl 9.0.3, which works like a charm.
Referenced by1
  • 94529656aeFix [b3fbd9a6e0]: string trim generates invalid utf-8 for some codepoints check-in2026-03-02 19:48:57
jan.nijtmanswiki2026-03-02 20:06:09

Fixed [here]

Thanks for the report and the patch.

Log in (anonymous is fine) to add a comment.