Tcl Source Code

View Ticket
Login
Ticket UUID: 3577801
Title: Issue with [file normalize] on Linux with symlink wtih ".."
Type: Bug Created on: 2012-10-17 09:28:35
Submitter: zoro2 Assigned to: dgp
Subsystem: 37. File System Severity:
Priority: 5 Medium Last modified: 2026-10-19 18:44:30
Status: Open Closed by:
Resolution: None Closed on:
Version: 8.6.18, 9.0.5, 9.1.0
Description:
Happend using latest Tcl 8.6b3 and 8.5.12. Code to reproduce (on Ubuntu Linux, ext3, but I doubt it matters).

set d [file join [file dirname [info script]] test]
catch {file delete -force $d}
file mkdir $d/d

close [open $d/f w]
close [open $d/d/f2 w]

exec ln -s f2 $d/d/l2
exec ln -s ../f $d/d/l

puts [vfs::filesystem fullynormalize $d/f]
puts [vfs::filesystem fullynormalize $d/d/l]
puts [vfs::filesystem fullynormalize $d/d/l2]
User Comments:
zoro2 added on 2012-10-17 18:50:04:
I have updated the script to show that the issue is with [file normalize] itself:

set d [file join [file dirname [info script]] test]
catch {file delete -force $d}
file mkdir $d/d

close [open $d/f w]
close [open $d/d/f2 w]

exec ln -s f2 $d/d/l2
exec ln -s ../f $d/d/l

puts [vfs::filesystem fullynormalize $d/f]
puts [file normalize $d/f]

puts ""
puts [vfs::filesystem fullynormalize $d/d/l]
# the first one returns test/d/f; second reports test/f
puts [file normalize $d/d/l/../../f]
puts [file normalize $d/d/l2/../../f]

puts ""
puts [vfs::filesystem fullynormalize $d/d/l2]
# the first one returns test/f2; second reports test/d/f2
puts [file normalize $d/d/l/../f2]
puts [file normalize $d/d/l2/../f2]

serhiy.storchaka added on 2026-10-19 18:44:30:

Still present in 8.6, 9.0 and 9.1: when ".." follows a link, the link target is used literally, so ".." or "." in the target, a trailing "/" or a chain of links give a wrong result (d/l/.. with l -> ../x gives d/..).

Proposed fix in branch normalize-dotdot-after-link, together with [3570244fff], [3183016fff] and [3099612fff]: on Unix the link target is normalized and further links are followed before backing up, so the results agree with realpath(). Tests filesystem-1.55 to 1.58. The last component of a path is still not resolved, as documented.