Inconsistent drive letter case on Windows

Aperta
#100,322 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
c, python

Direzione di ricerca

Inizia con il codice di gestione dei percorsi Windows in Modules/posixmodule.c intorno alle righe collegate, quindi riproduci il comportamento usando i comandi os.path.abspath riportati nel report. Verifica come viene ottenuta la lettera dell’unità e definisci come completamento la coerenza tra maiuscole e minuscole delle lettere di unità nei percorsi assoluti Windows, con il comportamento pertinente coperto da test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

OS-windows type-bug

Bug report + suggested fix

The os.path.abspath method on windows is inconsistent when pre-pending the drive letter as it can be either upper or lowercase.

It is not entirely clear from Microsoft's documentation (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew) when this happens exactly, but, a simple way of re-producing the issue is by changing directory and specifying the opposite case letter in the call

C:\Users\kieran>python -c "import os; print(os.path.abspath('.'))"
C:\Users\kieran

C:\Users\kieran>cd c:\Users\kieran\Projects

c:\Users\kieran\Projects>python -c "import os; print(os.path.abspath('.'))"
c:\Users\kieran\Projects

This is very frustrating when trying to compare paths, and, sometimes different tools in the same development environments will run in such a way that they change their drive letter case, leading to issues between those tools or differences inside tests.

I would like to suggest that we enforce the lowercase driver letters by making a small change to https://github.com/python/cpython/blob/0fe61d0838218b18bcff4bf434beba3e8dbcc42b/Modules/posixmodule.c#L4236-L4274

If we were to include an iteration (line 4266) of the buffered path that lowercased the chars up to the colon (guaranteed to be set), this would ensure consistent drive letters.

Your environment

Python 3.9.6
Microsoft Windows 10 Pro - 10.0.19044 Build 19044
x64-based PC

Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.