Overview
| Artifact ID: | 859648c476cd8c856910e14c5e7e76c291368ee598039c46ce1834e1135debfe |
|---|---|
| Ticket: | debd088e48998a758f2927b67c132341954428ea
llength split is different from string length |
| User & Date: | sebres on 2021-02-12 14:05:22 |
Changes
- icomment:
So you mean the situation where tcl routines following unicode string representation have totally different behavior as routines following utf-8 string representation is a normal?<br/> When exactly Tcl started to switch behaviour depending on string innards and used string function? For example using [string index]/[string length], it is possible to consider every char from surrogate pair, but [split] etc (so basically every stuff using Tcl_UtfNext, Tcl_UtPrev, Tcl_UtfToUniChar etc) missing that (deviates in behavior as for navigate or iterate over the string). Let alone such an issue in minor version upgrade is totally unexpected and can be well consider as a regression, the handling like this (different behavior depending on usage of function/command) is a nonsense, Jan. And no one language of the world behaves like this and has a weakness like this. Moreover, if you would take a look at python (basically not so good example, because python changes 2.x -> 3.x were a disaster as regards backwards compatibility), but just to note - they made a completely different switch. So the "progress" in Tcl looks so: <code><pre style="padding-left:10pt"> % puts "[info patchlevel]--[binary encode hex [encoding convertto utf-8 "\ud83e\udd1d"]]--[string length "\ud83e\udd1d"]" <b style="color:red">- 8.6.10--eda0beedb49d--2</b> <b style="color:green">+ 8.6.11--f09fa49d--2</b> % puts [info patchlevel]--[binary encode hex [encoding convertto utf-8 [split "\ud83e\udd1d" {}]]]--[binary encode hex [encoding convertto utf-8 [string index "\ud83e\udd1d" 0]]] <b style="color:red">- 8.6.10--eda0be20edb49d--eda0be</b> <b style="color:green">+ 8.6.11--f09fa49d--eda0be</b> </pre></code> And totally reverse picture in a python comparison: <code><pre style="padding-left:10pt"> >>> sys.version_info[0:2], u"\ud83e\udd1d".encode('utf-8', 'surrogatepass') <b style="color:red">- ((2, 7), '\xf0\x9f\xa4\x9d')</b> <b style="color:green">+ ((3, 8), b'\xed\xa0\xbe\xed\xb4\x9d')</b> </pre></code> So from point of view of python how tcl handles that now would be rather a "degradation" :) at least they went in totally another direction. Anyway regardless how one would implement the conversion between unicode and utf-8 representation of surrogates pairs, the different behavior by handling across different functions and tcl commands is definitely a bug, just because it is not consistent anymore.<br/> This means that such changes expecting more work and at least imply a completely rework of all the function in tcl-core, let alone the commands (like split etc using Tcl_UtfNext) which should completely switch to unicode representation now. I know where it is coming from and why or rather to cover what exactly, it was implemented this way (e. g. do you still know a "planting bombs" regression found in [bd94500678]?), but it is not a excuse for the inconsistency like this. This was lastly just a feature and not a security leak or so, and as such a feature it expecting a remaining of backwards compatibility and of course the consistency.<br/> In [c61818e4c9] I did suggest a branch as a solution for the problem which works more consistently and solves Tcl_UtfPrev flaws more sane (e. g. in [cdffcbaec97b94d2]) with considering of backwards compatibility and remaining index/length consistency between unicode and utf-8 representation. It's a mystery to me why a finally conclusion was to switch the behavior to follow an incompatible and inconsistent way. As a bottom line regarding the whole handling (no matter which representation of both is retained at end), I don't think this different behavior on functions can be considered as a feature. Sorry, but it is definitely a bug, Jan. - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Open"