|
2019-04-01
| ||
| 15:09 | • Closed ticket [b5cb29c639]: utf-8 from&to and / binary encoding&decodein... artifact: d3aaf3ff17 user: dgp | |
|
2019-02-22
| ||
| 10:05 | • Ticket [b5cb29c639]: 4 changes artifact: c37cc107ef user: oehhar | |
|
2019-02-21
| ||
| 16:09 | • Ticket [b5cb29c639]: 3 changes artifact: 9cdb9d5d4f user: bll | |
|
2019-02-19
| ||
| 16:48 | • Open ticket [b5cb29c639]. artifact: 4f55201549 user: anonymous | |
| 15:27 | • Closed ticket [b5cb29c639]. artifact: a8aaea2f18 user: jan.nijtmans | |
| 15:27 | • Ticket [b5cb29c639]: 3 changes artifact: effc660196 user: jan.nijtmans | |
| 14:57 | • New ticket [b5cb29c639]. artifact: 2d8bafa5af user: anonymous | |
utf-8 from&to and / binary encoding&decodeing conversation not the same
this string "Vašco da Gama äüö € é" cannot be preserved by converting or base64.
--------------------------------------------
testcode output
--------------------------------------------
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
tcl_platform(osVersion) = 4.1.12-94.2.1.el6uek.x86_64
tcl_platform(pathSeparator) = :
tcl_platform(platform) = unix
tcl_platform(pointerSize) = 4
tcl_platform(threaded) = 1
tcl_platform(user) = tbasien
tcl_platform(wordSize) = 4
8.6.8
Vašco da Gama äüö € é (Va\u0161co da Gama \u00E4\u00FC\u00F6 \u20AC \u00E9)
Vaaco da Gama äüö ¬ é (Vaaco da Gama \u00E4\u00FC\u00F6 \u00AC \u00E9)
Vaaco da Gama äüö ¬ é (Vaaco da Gama \u00C3\u00A4\u00C3\u00BC\u00C3\u00B6 \u00C2\u00AC \u00C3\u00A9)
Vaaco da Gama äüö ¬ é (Vaaco da Gama \u00C3\u00A4\u00C3\u00BC\u00C3\u00B6 \u00C2\u00AC \u00C3\u00A9)
--------------------------------------------
testcode
-------------------------------------------
proc u2x s {
set res {}
foreach c [split $s {}] {
scan $c %c int
append res [expr {$int<128? $c :"\\u[format %04.4X $int]"}]
}
set res
}
proc p {s} {
puts "$s ([u2x $s])"
}
encoding system utf-8
parray tcl_platform
puts $tcl_patchLevel
# Va\u0161co da Gama \u00E4\u00FC\u00F6 \u20AC \u00E9
# this string is utf-8
set i "Vašco da Gama äüö € é"
# this conventions do not end in the same as the input string
set a [binary decode base64 [binary encode base64 $i]]
set b [encoding convertto utf-8 [encoding convertfrom utf-8 $i]]
set c [encoding convertto utf-8 [binary decode base64 [binary encode base64 [encoding convertfrom utf-8 $i]]]]
p $i
p $a
p $b
p $c
Looks like the "encoding convertto" and "encoding convertfrom" are interchanged. See: [950acd6df4cffdac6dfecd189864e86262c33ea5] for an explanation why.
Closing as invalid
I saw the article mention. But cannot really match this. So I reopend that for further comments.
I am wondering, that a binary encoding/decodeing ends indifferent results.
set a [binary decode base64 [binary encode base64 $i]]
Will we not expect, that {$a eq $i}?
I edit the headline for that ticket to make it more clear.
You cannot do a direct conversion of the Tcl internal representation. % set i "Vašco da Gama äüö € é" Vašco da Gama äüö € é % set f [binary encode base64 $i] VmFhY28gZGEgR2FtYSDk/PYgrCDp % set g [binary decode base64 $f] Vaaco da Gama äüö ¬ é % set q [encoding convertto utf-8 $i] VaÅ¡co da Gama äüö ⬠é % set f [binary encode base64 $q] VmHFoWNvIGRhIEdhbWEgw6TDvMO2IOKCrCDDqQ== % set g [binary decode base64 $f] VaÅ¡co da Gama äüö ⬠é % set h [encoding convertfrom utf-8 $g] Vašco da Gama äüö € é %
Dear amitego,
you need binary data (bytes) for "binary encode base64". If you feed-in non-ninary data, the result is undefined.
Lets take the string "ä". This is one character of the unicode codepoint \u00e4. By chance, the value is below \u00ff, so a conversion to binary does not harm and the character passes.
Lets take the character "š". This is one character of the unicode codepoint \u0161. If this is treated as binary, only the lower byte is retained. This results in \u0061 which corresponds to the character "a".
You observe this transformation in your example.
To transform a string into binary data, an encoding is required. If you choose "utf-8", you get:
% set u [encoding convertto utf-8 š] Å¡ % string length $u 2 % scan $u %c%c 197 161
This representation may be used by binary encode.
I hope, it is getting clearer what happens. It is difficult but very powerful.
Hope this helps, Harald