Issue 23463: Incorrect behaviour when opening files containing colons on Windows (original) (raw)

Issue23463

Created on 2015-02-14 11:54 by Artfunkel, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg235964 - (view) Author: Tom Edwards (Artfunkel) Date: 2015-02-14 11:54
Consider this script: f = open("bug>test.txt",'w') f.write("hello") f.close() On Windows the first line will throw an OSError exception because the character '>' is not valid in an NTFS filename. This is correct. Now consider this script: f = open("bug:test.txt",'w') f.write("hello") f.close() This script will complete without error, and f.write will return 5. This despite the colon character also being invalid in NTFS filenames! The output of the second script is an empty file called "bug" in the working directory. I expect it to throw the same exception as the first script.
msg235965 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2015-02-14 12:09
Colons are valid in filenames to introduce Alternate Data Stream: https://msdn.microsoft.com/en-us/library/cc422524.aspx
msg235966 - (view) Author: Tom Edwards (Artfunkel) Date: 2015-02-14 12:48
Ha! What a feature. Thanks for the link. Maybe I'm rehashing old arguments, but I still think that Python's behaviour in this case is wrong. This is very surprising behaviour to anyone who isn't intimately familiar with NTFS and should not be something that in invoked silently. Currently *everyone* who wants to open a file is expected to perform their own test for colons in the path, particularly those who are generating filenames from user data. (Unless they actually want to write to an alternate stream of course, but how often does that happen?) This is behaviour also introduces a cross-platform inconsistency, as a filename on NTFS means something slightly different from a filename on any other file system. Would it be wise for open() to only accept NTFS alternate stream path syntax if a special character is present in the 'mode' argument?
msg235967 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-02-14 12:54
Python just exposes the OS filename semantics, it doesn't judge them :) This is just as true on linux as it is on Windows.
History
Date User Action Args
2022-04-11 14:58:12 admin set github: 67651
2015-02-14 12:54:58 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: not a bug
2015-02-14 12:48:56 Artfunkel set status: closed -> openresolution: not a bug -> (no value)messages: + components: - Windows
2015-02-14 12:09:39 tim.golden set status: open -> closedresolution: not a bugstage: resolved
2015-02-14 12:09:16 tim.golden set messages: +
2015-02-14 12:02:18 SilentGhost set nosy: + tim.golden, zach.ware, steve.dowercomponents: + Windows
2015-02-14 11:54:00 Artfunkel create