Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-05-01
07:38
Fix more corner-cases like [0e92c404f19ede5b2eb06e6db27647d3138cc56|0e92c404f1]: The only place wher... check-in: 91be696bf3 user: jan.nijtmans tags: core-8-5-branch
2014-04-30
21:59
Better (safer) fix for [0e92c404f1] check-in: b8c06f813e user: jan.nijtmans tags: core-8-5-branch
20:38 • Closed ticket [0e92c404f1]: Side effect on string range command (from encoding a... artifact: 685bd28123 user: jan.nijtmans
20:22
Fix [0e92c404f1]: Side effect on string range command (from encoding and format commands) closed check-in: 77a7d8d123 user: jan.nijtmans tags: mistake
16:54 • New ticket [0e92c404f1] Side effect on string range command (from encoding and f... artifact: ac313facd8 user: anonymous

Side effect on string range command (from encoding and format commands)

Closed / Fixed0e92c404f19ede5b2eb06e6db27647d3138cc56fCreated 13 years agoUpdated 13 years ago
Descriptionplain2014-04-30 16:54:49
Hi all,

I found one very confusing behavior in tcl.

set x "\u5317\u4eac"             # Beijing in Chinese
set y $x
puts "x: '$x' -> '[string range $x 0 100]''"
puts "y: '$y'"
encoding convertfrom "iso8859-1" $y
puts "y: '$y'"
# format "%s" $y
puts "x: '$x' -> '[string range $x 0 100]'"

output:
x: '北京' -> '北京''
y: '北京'
y: '北京'
x: '北京' -> '¬'


if we uncomment second to last line above output is ok:

x: '北京' -> '北京''
y: '北京'
y: '北京'
x: '北京' -> '北京'



encoding and format commands have side effects on string range command (In the second example they negate each other producing good result). Pay attention that neither x nor y were manipulated in any way. However string range command seems to be affected. I use tcl 8.5.

Thanks,
Nikola
Referenced by2
jan.nijtmanswiki2014-04-30 20:38:01

Fixed in [77a7d8d123] (core-8-5-branch). In trunk, the fix was already applied more than 5 years ago ([ee4709ceaf], thanks to dkf), so I just backported dkf's fix.

Explanation: The "encoding convertfrom" command creates an internal byte array representation from the string, and "string range" tries to make smart use of the byte array representation. But that shortcut was simply wrong.

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