Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: fb9e5f9d85cf0b7da234e6d9c3b867bf42a922a484e6a7cd6f1d76c182b360b8
Ticket: dd010cadfb99cee6c0a38d1bd4f4927a4945f4ec
[string trim] mishandles surrogates
User & Date: jan.nijtmans on 2020-04-06 20:08:18
Changes

  1. 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
    
  2. login: "jan.nijtmans"
  3. mimetype: "text/plain"