fix(cmd): Git.polish_url mein remote URLs ko bina badle rakhein by Keerthana-64 · Pull Request #2370 · gitpython-developers/GitPython
Repository navigation
fix(cmd): Git.polish_url mein remote URLs ko bina badle rakhein - #2370
Closed
Keerthana-64 wants to merge 1 commit into gitpython-developers:main from Keerthana-64:polish-url-remote-hosts
Closed
fix(cmd): Git.polish_url mein remote URLs ko bina badle rakhein #2370 Keerthana-64 wants to merge 1 commit into gitpython-developers:main from Keerthana-64:polish-url-remote-hosts
Conversation
Keerthana-64 commented Nov 26, 2026
Copy link Copy Markdown
Contributor
Git.polish_url ne Cygwin ke bahar URL ke har backslash () ko slash (/) mein badal diya tha. Repo._clone, Remote.create aur RootModule.update har clone ya stored remote URL ko is function se pass karte hain. Ismein .gitmodules se padhe gaye submodule URLs bhi shamil hain.
Git (libcurl ke through) aur urllib ne http://localhost:18472\@127.0.0.1:18471/lib.git ko alag-alag tareeke se samjha. Inhone localhost:18472\ ko userinfo aur 127.0.0.1:18471 ko host maana. Lekin GitPython ne Git ko wahi URL http://localhost:18472/@127.0.0.1:18471/lib.git ke roop mein diya.
Is URL ke saath .gitmodules mein git submodule update --init ne 127.0.0.1:18471 se connection banaya, jabki Repo.submodule_update(init=True) aur Repo.clone_from ne dono backends par localhost:18472 se connection banaya.
Saath hi, Submodule.url mein original string hi dikh rahi thi. Is wajah se URL ke basis par check karne wali host allowlist us host ko sahi tarah verify nahi kar pa rahi thi jisse GitPython actually connect karta hai.
Ab polish_url un strings ko bina badle chhod deta hai jo URL scheme se shuru hoti hain ya jinmein do ya usse zyada characters wala SCP-style host hota hai.
Submodule.add bhi Windows-only to_native_path_linux call se pehle yahi check use karta hai.
Drive-letter paths, ~ paths aur file: URLs pehle ki tarah convert hote rahenge.
test/test_clone.py mein do naye tests add kiye gaye hain. Ye tests dono backends par pehle fail hote the aur ab pass hote hain.
macOS par Git 2.54.0 ke saath full test suite, pre-commit, mypy, basedpyright aur docs build sab successfully pass hue.
Windows-only Submodule.add path ko Windows par run nahi kiya gaya.
fix(cmd): leave remote URLs unchanged in Git.polish_url
30879d2
`Git.polish_url` replaced every backslash with `/` outside Cygwin so that Windows paths stored in configuration use forward slashes. It runs on every clone URL in `Repo._clone`, which covers `Repo.clone_from()` and the submodule clones of `Submodule.update()` and `RootModule.update()`, on the URL passed to `Remote.create()`, and on the URL `RootModule.update()` stores for a changed `.gitmodules` entry. In a URL a backslash is an ordinary character, and replacing it can move the end of the authority: - Git (through libcurl) and `urllib.parse` read `http://localhost:18472\@127.0.0.1:18471/lib.git` as userinfo `localhost:18472\` and host `127.0.0.1:18471`. - GitPython handed Git `http://localhost:18472/@127.0.0.1:18471/lib.git`, whose host is `localhost:18472`. With that URL in `.gitmodules` and an HTTP listener on each port, `git submodule update --init` contacted `127.0.0.1:18471`, while `Repo.submodule_update(init=True)` and `Repo.clone_from()` contacted `localhost:18472` on both backends. `Submodule.url` still reported the original string, so a host allowlist checked against that URL, with `urllib` or with Git, did not bound the host GitPython connected to. `.gitmodules` is untrusted repository content, and a service that validates a user-supplied clone URL's host before calling `Repo.clone_from()` is affected the same way. `Submodule.add()` made the same replacement on Windows through `to_native_path_linux()`. `polish_url` now returns a string unchanged when it starts with a URL scheme or scp-style host of at least two characters, using Git's scheme characters, followed by a colon. Strings without such a prefix, including one-letter Windows drive paths, `~` paths and `file:` URLs, are converted exactly as before, and the Cygwin branch is untouched (`cygpath` already leaves URLs such as `https://...` alone). `Submodule.add()` applies the same test before `to_native_path_linux()`. Unsafe-protocol checks still run on the URL Git receives. `test_clone_from_passes_remote_url_unchanged` and `test_polish_url_converts_backslashes_only_in_local_paths` in `test/test_clone.py` fail before the change and pass after on the `cli` and `gix` backends, and every request in the reproduction above now reaches `127.0.0.1:18471`. The full test suite passes on both backends with Git 2.54.0, GixPython 0.3.0 and CPython 3.13 on macOS; `pre-commit`, `mypy`, `basedpyright --warnings` and the Sphinx build pass. The Windows-only `Submodule.add()` path was not exercised on Windows. Agent-Model: claude-opus-5-5
Byron commented Nov 26, 2026
Copy link Copy Markdown
Member
|
Closing this based on the changed contributing guidelines: missing reference to downstream bug or problem. |