Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve(strict=True) is not case-sensitive on Windows and Python 2.7 #84

Open
simonDarmstadt opened this issue Mar 9, 2023 · 4 comments

Comments

@simonDarmstadt
Copy link

Good day ladies and gentlemen,

I have a problem with the pathlib2.Path().resolve(strict=True) and python-2.
This function is case-sensitive when running with python-3 but not when run with python-2.

In the example in the screenshot I would expect pathlib2.Path("C:/temp/garbage.txt").resolve(strict=True) to return C:/temp/gArbage.txt instead of C:/temp/garbage.txt.

See screenshot (old screenshot where I tested python-3 agains pathlib):
grafik

I tested on Windows 10 with python-2.7.17, pathlib2-2.3.3 and pathlib2-2.3.7.post1.

I doublechecked python-3.7.5 with pathlib2-2.3.7.post1. This will resolve correctly. So it is a python-2 specific problem.

grafik

Thanks in advance for looking into it!

@mcmtroffaes
Copy link
Collaborator

Thanks for reporting this and I'm sorry nobody has responded to this yet. Though perhaps there might be something that could be done, the library is no longer maintained on Python 2.7...

Anyway, the code responsible for this is likely at https://github.com/jazzband/pathlib2/blob/develop/src/pathlib2/_ntpath.py which was backported (i.e. copied) from CPython 3.x at some point. An upstream resync might fix it (or not... in which case we'd have to dig deeper).

@hendrikmakait What do you think?

@mcmtroffaes mcmtroffaes changed the title resolve(stricht=True) is not case-sensitive on windows resolve(strict=True) is not case-sensitive on Windows and Python 2.7 Aug 4, 2023
@mcmtroffaes
Copy link
Collaborator

Apologies, I made a mistake in my analysis. The old Python 2.7 version uses the develop-py2 branch whilst I was looking at the develop branch which is Python 3.x only. The correct reference is:

https://github.com/jazzband/pathlib2/blob/develop-py2/pathlib2/__init__.py#L1487

mcmtroffaes added a commit that referenced this issue Aug 4, 2023
@mcmtroffaes
Copy link
Collaborator

I added a quick regression test for this. Unfortunately the test passes on my system, so I'm at loss as to how to reproduce this... For the record, the test lives here (it's on top of the develop-py2 branch):

421333f

@mcmtroffaes
Copy link
Collaborator

Here's a slightly corrected version that actually tests the case problem:

develop-py2...feature/test-issue-84

Note that Path("fileA") == Path("filea") even though repr(Path("fileA")) != repr(Path("filea")).

Whilst ideally canonicalizing paths (such as with resolve) would also ensure their case is as on the filesystem on Windows, the implementation on Python 2.7 simply doesn't do that because it is missing some built-in functions that are only available on Python 3.x. In my opinion, adding those in is likely a non-trivial undertaking, and will be more than a one-line patch that could be put in a quick post release. Couple that with Python 2.7 being EOL for a really long time now, it seems not worth the effort and risk of trying to properly fix this now, in my opinion.

If possible, if you really still need to rely on Python 2.7, I recommend that you write your code so you don't rely on case sensitivity on Windows, as the API doesn't make such promise (though it behaves that way on Python 3.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants