.
D 2021-02-12T14:05:22.004
J icomment So\syou\smean\sthe\ssituation\swhere\stcl\sroutines\sfollowing\sunicode\sstring\srepresentation\shave\stotally\sdifferent\sbehavior\sas\sroutines\sfollowing\sutf-8\sstring\srepresentation\sis\sa\snormal?<br/>\r\nWhen\sexactly\sTcl\sstarted\sto\sswitch\sbehaviour\sdepending\son\sstring\sinnards\sand\sused\sstring\sfunction?\r\n\r\nFor\sexample\susing\s[string\sindex]/[string\slength],\sit\sis\spossible\sto\sconsider\severy\schar\sfrom\ssurrogate\spair,\sbut\s[split]\setc\s(so\sbasically\severy\sstuff\susing\sTcl_UtfNext,\sTcl_UtPrev,\sTcl_UtfToUniChar\setc)\smissing\sthat\s(deviates\sin\sbehavior\sas\sfor\snavigate\sor\siterate\sover\sthe\sstring).\r\n\r\nLet\salone\ssuch\san\sissue\sin\sminor\sversion\supgrade\sis\stotally\sunexpected\sand\scan\sbe\swell\sconsider\sas\sa\sregression,\sthe\shandling\slike\sthis\s(different\sbehavior\sdepending\son\susage\sof\sfunction/command)\sis\sa\snonsense,\sJan.\sAnd\sno\sone\slanguage\sof\sthe\sworld\sbehaves\slike\sthis\sand\shas\sa\sweakness\slike\sthis.\r\n\r\nMoreover,\sif\syou\swould\stake\sa\slook\sat\spython\s(basically\snot\sso\sgood\sexample,\sbecause\spython\schanges\s2.x\s->\s3.x\swere\sa\sdisaster\sas\sregards\sbackwards\scompatibility),\sbut\sjust\sto\snote\s-\sthey\smade\sa\scompletely\sdifferent\sswitch.\r\nSo\sthe\s"progress"\sin\sTcl\slooks\sso:\r\n<code><pre\sstyle="padding-left:10pt">\r\n%\sputs\s"[info\spatchlevel]--[binary\sencode\shex\s[encoding\sconvertto\sutf-8\s"\\ud83e\\udd1d"]]--[string\slength\s"\\ud83e\\udd1d"]"\r\n<b\sstyle="color:red">-\s8.6.10--eda0beedb49d--2</b>\r\n<b\sstyle="color:green">+\s8.6.11--f09fa49d--2</b>\r\n\r\n%\sputs\s[info\spatchlevel]--[binary\sencode\shex\s[encoding\sconvertto\sutf-8\s[split\s"\\ud83e\\udd1d"\s{}]]]--[binary\sencode\shex\s[encoding\sconvertto\sutf-8\s[string\sindex\s"\\ud83e\\udd1d"\s0]]]\r\n<b\sstyle="color:red">-\s8.6.10--eda0be20edb49d--eda0be</b>\r\n<b\sstyle="color:green">+\s8.6.11--f09fa49d--eda0be</b>\r\n</pre></code>\r\nAnd\stotally\sreverse\spicture\sin\sa\spython\scomparison:\r\n<code><pre\sstyle="padding-left:10pt">\r\n>>>\ssys.version_info[0:2],\su"\\ud83e\\udd1d".encode('utf-8',\s'surrogatepass')\r\n<b\sstyle="color:red">-\s((2,\s7),\s'\\xf0\\x9f\\xa4\\x9d')</b>\r\n<b\sstyle="color:green">+\s((3,\s8),\sb'\\xed\\xa0\\xbe\\xed\\xb4\\x9d')</b>\r\n</pre></code>\r\nSo\sfrom\spoint\sof\sview\sof\spython\show\stcl\shandles\sthat\snow\swould\sbe\srather\sa\s"degradation"\s:)\sat\sleast\sthey\swent\sin\stotally\sanother\sdirection.\r\n\r\nAnyway\sregardless\show\sone\swould\simplement\sthe\sconversion\sbetween\sunicode\sand\sutf-8\srepresentation\sof\ssurrogates\spairs,\sthe\sdifferent\sbehavior\sby\shandling\sacross\sdifferent\sfunctions\sand\stcl\scommands\sis\sdefinitely\sa\sbug,\sjust\sbecause\sit\sis\snot\sconsistent\sanymore.<br/>\r\nThis\smeans\sthat\ssuch\schanges\sexpecting\smore\swork\sand\sat\sleast\simply\sa\scompletely\srework\sof\sall\sthe\sfunction\sin\stcl-core,\slet\salone\sthe\scommands\s(like\ssplit\setc\susing\sTcl_UtfNext)\swhich\sshould\scompletely\sswitch\sto\sunicode\srepresentation\snow.\r\n\r\nI\sknow\swhere\sit\sis\scoming\sfrom\sand\swhy\sor\srather\sto\scover\swhat\sexactly,\sit\swas\simplemented\sthis\sway\s(e.\sg.\sdo\syou\sstill\sknow\sa\s"planting\sbombs"\sregression\sfound\sin\s[bd94500678]?),\sbut\sit\sis\snot\sa\sexcuse\sfor\sthe\sinconsistency\slike\sthis.\sThis\swas\slastly\sjust\sa\sfeature\sand\snot\sa\ssecurity\sleak\sor\sso,\sand\sas\ssuch\sa\sfeature\sit\sexpecting\sa\sremaining\sof\sbackwards\scompatibility\sand\sof\scourse\sthe\sconsistency.<br/>\r\nIn\s[c61818e4c9]\sI\sdid\ssuggest\sa\sbranch\sas\sa\ssolution\sfor\sthe\sproblem\swhich\sworks\smore\sconsistently\sand\ssolves\sTcl_UtfPrev\sflaws\smore\ssane\s(e.\sg.\sin\s[cdffcbaec97b94d2])\swith\sconsidering\sof\sbackwards\scompatibility\sand\sremaining\sindex/length\sconsistency\sbetween\sunicode\sand\sutf-8\srepresentation.\sIt's\sa\smystery\sto\sme\swhy\sa\sfinally\sconclusion\swas\sto\sswitch\sthe\sbehavior\sto\sfollow\san\sincompatible\sand\sinconsistent\sway.\r\n\r\nAs\sa\sbottom\sline\sregarding\sthe\swhole\shandling\s(no\smatter\swhich\srepresentation\sof\sboth\sis\sretained\sat\send),\sI\sdon't\sthink\sthis\sdifferent\sbehavior\son\sfunctions\scan\sbe\sconsidered\sas\sa\sfeature.\sSorry,\sbut\sit\sis\sdefinitely\sa\sbug,\sJan.
J login sebres
J mimetype text/x-fossil-wiki
J status Open
K debd088e48998a758f2927b67c132341954428ea
U sebres
Z 1622d93de70f25c3c893c78492ca635e