Tcl Source Code

View Ticket
Login
Ticket UUID: 9c5a00c69df3018e4077b5ea19e235f62dbe0a67
Title: Multiple issues with tilde expansion on Windows
Type: Bug Version: 8.6
Submitter: apnadkarni Created on: 2023-03-04 03:06:38
Subsystem: - New Builtin Commands Assigned To: apnadkarni
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-03-07 02:58:55
Resolution: Fixed Closed By: apnadkarni
    Closed on: 2023-03-07 02:58:55
Description:

Somewhere in the 8.6 development, probably with this commit, an inconsistency is introduced between Unix and Windows. To quote the manpages,

If a file name starts with a tilde, then the file name will be interpreted as if the first element is replaced with the location of the home directory for the given user. If the tilde is followed immediately by a separator, then the $HOME environment variable is substituted. Otherwise the characters between the tilde and the next separator are taken as a user name, which is used to retrieve the user's home directory for substitution.

Unix conforms to the documented behavior.

% set env(HOME) /tmp
/tmp
% file normalize ~
/tmp
% file normalize ~apnadkarni
/home/apnadkarni

However on Windows,

% file norm ~
C:/Users/apnad/Documents
% file norm ~ashok
C:/Users/apnad/Documents
% set env(HOME) D:\\temp
D:\temp
% file norm ~
D:/Temp
% file norm ~ashok
D:/Temp

Note how ~ashok also follows setting of HOME.

One might find the behavior on Windows more natural but it is not what is documented.

Will fix for 8.6/8.7/9.0 if there are no objections.

/Ashok

User Comments: apnadkarni added on 2023-03-04 15:10:02:
There are other issues with tilde on Windows as well.

NetUserGetInfo generally returns an empty string for the home directory in some scenarios,for example when the user account was originally a Microsoft account (and may be even when the current account is a Microsoft account, no means for me to test). Tcl then just assumes home directory is the directory of the same name within the default profiles directory.

The other additional issue is it looks in system.ini for the user account which is no longer valid in Windows NT.

All three are addressed in the bug-9c5a00c69d branch.

apnadkarni added on 2023-03-04 10:34:27:
Yes, looks like it though it appears the fix did a little more than intended. Will change for 8.6 onwards.

jan.nijtmans added on 2023-03-04 10:23:46:

No objections at all from me!

It looks like this change done, originating from [this] bugfix. It looks like you (@Ashok) was involved in that discussion)