Artifacts Associated With Ticket dd010cadfb
Ticket change [383e9a20ab] (rid 181214) by dgp on 2020-04-06 14:42:19:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Many expectations and invariants are violated. Trimming a string makes a longer string? Order of trimming left/right gives different results? % set orig \U1F4A9 💩 % set remove \U1F4AA 💪 % string length $orig 2 % string length [string trimleft $orig $remove] 3 % string length [string trimright $orig $remove] 0 % string length [string trim $orig $remove] 3 % string length [string trimleft [string trimright $orig $remove] $remove] 0 % string length [string trimright [string trimleft $orig $remove] $remove] 3
- foundin initialized to: "8.7"
- is_private initialized to: "0"
- login: "dgp"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "10. Objects"
- title initialized to: "[string trim] mishandles surrogates"
- type initialized to: "Bug"
Ticket change [c68630f35b] (rid 181215) by jan.nijtmans on 2020-04-06 15:00:13:
- icomment:
So ... just don't do that :-) "string trim" expects a set of characters as 3th element. Since Emoji are split into 2 surrogates, it starts removing matching surrogates, indeed totally different as expected. My suggestion: Don't allow Emoji to be used in 3th argument of "string trim" The same happens when using Emoji between '[' and ']' in regular expressions. Solution: Switch to Tcl 9.0. Enhance documentation of "string trim" and regsub/regexp explaining this as known limitation.
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [a1a0a45549] (rid 181216) by dgp on 2020-04-06 15:40:33:
- icomment:
This "solution" places an input restriction burden on every algorithm that relies on [string trim*] to keep expected invariants in its behavior. The problem isn't that any programmer would want to do foolish things like this, it is that the commands are now vulnerable to these inputs in ways they were not before. I want people to adopt Tcl 9 too, but I don't want to force the issue by breaking Tcl 8 and then documenting the breakage.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [fb9e5f9d85] (rid 181217) by jan.nijtmans on 2020-04-06 20:08:18:
- icomment:
OK, let's do the same with tclsh8.6, on MacOS this time (current core-8-6-branch): $ tclsh8.6 % set orig \uD83D\uDCA9 💩 % set remove \uD83D\uDCAA 💪 % string length $orig 2 % string length [string trimleft $orig $remove] 1 % string length [string trimright $orig $remove] 2 % string length [string trim $orig $remove] 1 % string length [string trimleft [string trimright $orig $remove] $remove] 1 % string length [string trimright [string trimleft $orig $remove] $remove] 1 This looks more reasonable. Hm, indeed, something strange is going on. My results on MacOS with 8.7 (current core-8-branch): $ tclsh8.7 % set orig \uD83D\uDCA9 💩 % set remove \uD83D\uDCAA 💪 % string length $orig 2 % string length [string trimleft $orig $remove] 3 % string length [string trimright $orig $remove] 0 % string length [string trim $orig $remove] 3 % string length [string trimleft [string trimright $orig $remove] $remove] 0 % string length [string trimright [string trimleft $orig $remove] $remove] 3 Same as yours, this result cannot be explained by considering a split into 2 surrogates. Yes, something more weird is going on. I see your point
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [f4f6555324] (rid 181218) by jan.nijtmans on 2020-04-06 20:08:35:
- assignee changed to: "jan.nijtmans"
- login: "jan.nijtmans"
- mimetype: "text/plain"
Ticket change [a1b360302d] (rid 181224) by jan.nijtmans on 2020-04-06 20:55:49:
- icomment:
Fixed in [b2cf8c2a88]. Solution surprisingly simple.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [8ab627a583] (rid 181225) by jan.nijtmans on 2020-04-06 20:56:07:
- closedate changed to: "2458946.37230546"
- closer changed to: "jan.nijtmans"
- login: "jan.nijtmans"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"