Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: de6df813f6f3a77b322b51379a0cc890f67b4baaabbfa37e95b0509809b23e87
Ticket: bcd1004104651998d1ae99aa6869e249c0ed0019
A change to the system encoding, a stale cached file FsPath object, and an incorrect result
User & Date: pooryorick on 2019-10-22 14:27:51
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    The ext file system has no concept of "encoding":  It names a file exactly the
    sequence of octets it is handed.  In the following script, iso8859-1 is used to
    create a file, and then that same sequence of octets is obtained using
    <code>glob</code>.  Then an FsPath object created under a different system
    encoding is created and cached.  Later on that FsPath object is used under the
    original system encoding when it shouldn't be.
    
    <code><verbatim>
    set name  登鸛鵲樓
    
    encoding system iso8859-1
    
    # create an iso8859-1-compatible sequence of octets to name the file by.
    # They happen to be a string encoded in utf-8, but that's irrelevant.
    set utf8 [encoding convertto utf-8 $name]
    
    set chan [open $utf8 w]
    puts $chan hello
    close $chan
    
    #
    lassign [glob -directory [pwd] *$utf8*] fname
    
    # A file named by that sequence of octets exists. 
    puts [list iso8859-1 [file exists $fname]] ;#-> 1
    
    
    encoding system utf-8
    
    # The sequence of octets is now itself converted to utf-8. Such a file does not
    # exist, and a FsPath object has been cached.  So far so good.
    puts [list utf-8 [file exists $fname]] ;#-> 0
    encoding system iso8859-1
    
    # Here the answer here should be 1, but the FsPath object created under a
    # previous system encoding is used when it shouldn't be.
    puts [list iso8859-1 [file exists $fname]]  ;# -> 0
    
    # Discard the cached FsPath object, causing a new FsPath to be created using
    # the (currently correct) system encoding.
    puts [list iso8859-1 {string range} [file exists [string range $fname 0 end]]]  ;# -> 1
    </verbatim></code>
    
  5. is_private changed to: "0"
  6. login: "pooryorick"
  7. priority changed to: "5 Medium"
  8. resolution changed to: "None"
  9. severity changed to: "Important"
  10. status changed to: "Open"
  11. submitter changed to: "pooryorick"
  12. subsystem changed to: "37. File System"
  13. title changed to:
    A change to the system encoding, a stale cached file FsPath object, and an incorrect result
    
  14. type changed to: "Bug"