Tcl Source Code

View Ticket
Login
Ticket UUID: e3da32d8169e7584f93dea8592f1f5b9a37f0413
Title: max os x [glob] returns the decomposed filenames
Type: Bug Created on: 2015-04-21 05:03:23
Submitter: anonymous Assigned to: jan.nijtmans
Subsystem: 44. UTF-8 Strings Severity: Important
Priority: 4 Last modified: 2015-05-31 08:33:30
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.3
Description:
On the mac, a [glob] will return the decomposed utf-8 form of the filename.
glob should convert the filenames to the standard utf-8 format.
An encoding to convert these might also be useful.

#!/opt/local/bin/tclsh
#
# references
#     http://stackoverflow.com/questions/6153345/different-utf8-encoding-in-filenames-os-x
#     https://developer.apple.com/library/mac/qa/qa1173/_index.html

set orig {aĆ”}
set fh [open $orig w]
close $fh
set fnlist [glob -nocomplain a*]
foreach {fn} $fnlist {
  if { ! [regexp {^a} $fn] } {
    continue
  }
  puts "orig:$orig"
  puts "  fn:$fn"
  if { $orig == $fn } {
    puts "  equal"
  } else {
    puts "  not equal"
  }
}
User Comments:
dkf added on 2015-05-16 06:01:10:

This is exactly why we need to put encoding normalization into Tcl as part of the unicode fixes. That's a lot of code, unfortunately. But we'll probably leave glob doing what it does now, since it's just telling you what is there, and will work correctly for the main use case of getting filenames so that you can use them with file-manipulating operations.


anonymous (claiming to be [email protected]) added on 2015-05-25 21:23:50:
This bug has been extant since 2003 ( http://sourceforge.net/p/tcl/bugs/2501/ ).

I guess I'm not in the main use case :), though I certainly agree -- most of the time, if the user is just dealing with files, it's not an issue.

anonymous (claiming to be [email protected]) added on 2015-05-31 08:33:30:
Here is the work around in case anyone else looks for this issue.
  set flist [glob *]
  set fn gfl.txt
  set fh [open $fn w]
  puts $fh $flist
  close $fh
  set flist [exec iconv -f UTF-8-MAC -t UTF-8 $fn]
  file delete $fn