unicode BOM not removed
Closed / Fixed218406ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:57:11
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
welch Closed ticket [218406ffff].
[History diff]2000-10-26 08:21:18
dgp Ticket [218406ffff]: 3 changes
[History diff]2001-04-06 03:26:08
Log in (anonymous is fine) to add a comment.