Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 09ce9b344128ea106b91ec88043e8d660bd2e687
Ticket: 218406ffffffffffffffffffffffffffffffffff
unicode BOM not removed
User & Date: nobody on 2000-10-26 00:57:11
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 5336 Bug
    Version: 8.3.1
    SubmitDate: '2000-05-03'
    LastModified: '2000-08-15'
    Severity: MED
    Status: Closed
    Submitter: angie
    ChangedBy: ericm
    OS: Windows 98
    Machine: pentium II
    FixedDate: '2000-10-25'
    ClosedDate: '2000-08-15'
    
    
    Tcl 8.3.1 Bug
    
    Name:  doug edmunds
    email:  [email protected]
    Support:  None
    Severity:  3
    OperatingSystem:  Windows 98
    Machine:  pentium II
    Synopsis:  unicode BOM not removed
    
    ReproducibleScript:
    BOM = Byte Order Mark sometimes placed at beginning of utf-16 files
    either FEFF or FFFE, signifying little-endian or big-endian format.
    
    
    1. "encoding convertfrom unicode"
    #fn is a unicode utf-16 file
    proc read_unifile {fn} {
     set f [open $fn r]
     set text [encoding convertfrom unicode [read $f ]]
     close $f
     return $text
     }
    call proc:  
    set result [read_unifile unifile.txt] 
    set $result  <<BOM not removed
    
    2.  fconfigure $file -encoding unicode
    
      proc file:uread {fn} {
        set encoding ""
        set f [open $fn r]
        if {[info tclversion]>=8.1} {
            gets $f line
            if {[regexp \xFE\xFF $line]||[regexp \xFF\xFE $line]} {
                fconfigure $f -encoding unicode
                set encoding unicode
            }
            seek $f 0 start ;# rewind -- real reading is still to come
        }
        set text [read $f [file size $fn]]
        close $f
        if {$encoding=="unicode"} {
    regsub -all "\uFEFF|\uFFFE" $text "" text
        }
        return $text
      }
    
    set result [file:uread unifile.txt] 
    set $result  <<BOM was not removed
    
    
    ObservedBehavior:
    BOM must be manually removed.
    If the unicode file being read in will be evaluated,
    it will fail as a script, as in
    eval $result
    
    
    DesiredBehavior:
    BOM, if present, automatically removed when file is loaded
    
    Patch:
    assuming string that file is stored into is named $text
    
    regsub -all "\uFEFF|\uFFFE" $text "" text
    
    
    My reading of the UTF BOM FAQ is that Tcl should _not_ automatically remove the BOM.  The use of a BOM is protocol dependant, so information about its presence or absence may be relevant to a developer using Tcl.  In addition, depending on the protocol, the BOM may actually be data (specifically, a zero-width non-breaking space), so removing it could be incorrect.
    
    Please correct me if I am wrong; my information is derived from the UTF/BOM FAQ at:
    
    http://www.unicode.org/unicode/faq/utf_bom.html
    
       Eric Melski                            The Other Tcl Guy
       ericm at ajubasolutions.com            Ajuba Solutions
    
    -- 08/15/2000 ericm
    
    
    
  4. foundin changed to: "obsolete: 8.3.1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "57. zlib"
  10. title changed to: "unicode BOM not removed"
  11. type changed to: "Bug"