[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread R. David Murray
R. David Murray added the comment: Could WindowsPath (as opposed to PureWindowsPath) call samefile as part of the equality test? (I'm not familiar enough with pathlib to know if that is a nonsense question.) -- ___ Python

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread R. David Murray
R. David Murray added the comment: Maybe we could at least mention the issue (and perhaps link to samefile) in the "General Properties" section? -- nosy: +r.david.murray ___ Python tracker

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread Steve Dower
Steve Dower added the comment: Just tested something that I'd assumed and it turned out I was wrong: >>> p1 = PureWindowsPath(r"C:\a\b\..\c") >>> p2 = PureWindowsPath(r"C:\a\c") >>> p1 == p2 False >>> p1, p2 (PureWindowsPath('C:/a/b/../c'), PureWindowsPath('C:/a/c'))

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread Steve Dower
Steve Dower added the comment: > I think all programmers expect that if x == y, then they refer to the same > file. This is not true currently. Perhaps, but you could equally say that they expect that if x != y then they refer to different files, which is also not

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread Steve Dower
Steve Dower added the comment: (FWIW, I don't think your "security" argument is going to be very convincing, as this problem has been around for far too long to be treated as suddenly urgent. But up to you.) My fear is that if PureWindowsPath stops handling the >90%

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-23 Thread benrg
benrg added the comment: I don't know whether this clarifies it at all, but if x and y are Path objects, and x == y, I would expect also x.exists() == y.exists(), and x.read_bytes() == y.read_bytes(), and so on, unless there is a race condition. I think all programmers

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-22 Thread benrg
benrg added the comment: This bug is about paths that compare *equal*, but refer to *different* files. I agree that the opposite is not much of a problem (and I said so in the original comment). The reason I classified this as a security bug is that Python scripts using

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-22 Thread Steve Dower
Steve Dower added the comment: Arguably, a WindowsPath instance only represents the *path* and not the file located by the path. So the programmer has to take just as much responsibility as if they were using plain strings, except there are some conveniences added to

[issue32612] pathlib.(Pure)WindowsPaths can compare equal but refer to different files

2018-01-21 Thread benrg
New submission from benrg : (Pure)WindowsPath uses str.lower to fold paths for comparison and hashing. This doesn't match the case folding of actual Windows file systems. There exist WindowsPath objects that compare and hash equal, but refer to different files. For