Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 731ae5f5ce8f7d89af5f324679fa97686b0c4b18
Ticket: ded7528bffe8bdf4cf5ab9f327b50b207777378e
subst/regsub/format/scan gets confused by braces
User & Date: ericp on 2014-02-16 01:38:06
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    I was trying to write a function that would urlencode a string, with \uxxxx sequences.  http://rosettacode.org/wiki/JSON#Tcl led me to trying this code:
    
        set escaped1 [subst  \
                          [regsub -all {[\[\]\$\u0000-\u001f\u0080-\uffff]} \
                       $value2 {[format "\\\\u%04x" [scan {&} %c]]}]]
    
    which I thought worked.  However, it seems to drop characters when
    braces are involved:
    
    % set value {w1 on the <blah abc {} def > form}
    w1 on the <blah abc {} def > form
    % set value1 [string map [list "@" "<@@>"] $value]
    w1 on the <blah abc {} def > form
    % set value2 [string map [list "\\" "<@>"] $value1]
    w1 on the <blah abc {} def > form
    % set escaped1 [subst [regsub -all {[\[\]\\\{\\\}\$\u0000-\u001f\u0080-\uffff]}
    $value2 {[format "\\\\u%04x" [scan {&} %c]]}]]
    w1 on the <blah abc \u007b def > form
    
    The close-brace should appear as \u007d, but it's missing completely.
    
    Bug, or is there better usage?
    
  5. foundin changed to: "8.6"
  6. is_private changed to: "0"
  7. login: "ericp"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6d1053e9208f1074fd485c15cc0d7e49e190bac5"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "ericp"
  14. subsystem changed to: "18. Commands M-Z"
  15. title changed to: "subst/regsub/format/scan gets confused by braces"
  16. type changed to: "Bug"