This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incorrect behaviour when opening files containing colons on Windows
Type: behavior Stage: resolved
Components: IO Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Artfunkel, r.david.murray, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

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:12adminsetgithub: 67651
2015-02-14 12:54:58r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg235967

resolution: not a bug
2015-02-14 12:48:56Artfunkelsetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg235966

components: - Windows
2015-02-14 12:09:39tim.goldensetstatus: open -> closed
resolution: not a bug
stage: resolved
2015-02-14 12:09:16tim.goldensetmessages: + msg235965
2015-02-14 12:02:18SilentGhostsetnosy: + tim.golden, zach.ware, steve.dower
components: + Windows
2015-02-14 11:54:00Artfunkelcreate