Repository navigation
Commit 30879d2
committed
fix(cmd): leave remote URLs unchanged in
`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-5Git.polish_url
1 parent 51061f1 commit 30879d2
4 files changed
Lines changed: 36 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
638 | 642 | | |
639 | 643 | | |
640 | 644 | | |
| |||
862 | 866 | | |
863 | 867 | | |
864 | 868 | | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
865 | 872 | | |
866 | 873 | | |
867 | 874 | | |
868 | 875 | | |
869 | 876 | | |
870 | 877 | | |
871 | | - | |
| 878 | + | |
872 | 879 | | |
873 | 880 | | |
874 | 881 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
688 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
689 | 690 | | |
690 | 691 | | |
691 | 692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
474 | 495 | | |
475 | 496 | | |
476 | 497 | | |
| |||
0 commit comments