[BUG] Shorthand like git/git or jonas/tig is rejected because rstrip(".git") strips a character set

Aperta Adatta ai principianti
#3,715 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
git, python
Ambito
cli

Direzione di ricerca

Il bug è nella chiamata rstrip(".git") sul controllo del componente di percorso in src/apm_cli/models/dependency/reference.py, intorno alla riga 1526; rimuove un insieme di caratteri invece del suffisso. Inizia riproducendo con DependencyReference.parse("git/git") e poi guarda tests/unit/test_generic_git_urls.py. Il lavoro è completo quando i nomi abbreviati composti solo da '.', 'g', 'i', 't' vengono analizzati, owner/..git genera ancora l'errore di traversal e un test parametrizzato copre git, tig, gitit e git.git.

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

Descrizione

Describe the bug
DependencyReference.parse rejects shorthand dependencies whose repo or owner name is made only of the characters ., g, i and t. Examples are git/git, jonas/tig, gitgitgadget/git, owner/git and owner/gitit. The error is Invalid repository path component: git.

The cause is src/apm_cli/models/dependency/reference.py line 1526:

if not re.match(allowed_pattern, part.rstrip(".git")):

rstrip takes a set of characters. It does not remove a suffix. So git becomes an empty string and the pattern check fails.

The maintainer already named this cause in a review note on merged PR #437 (2026-03): "The .rstrip('.git') call strips individual chars from the set {'.','g','i','t'} rather than the suffix '.git'. This is pre-existing and not introduced by this PR." I found no issue or PR that followed up, and the line is unchanged on main. I am filing this to add the user impact and offer a fix.

To Reproduce

  1. Check out main at fe6f089.
  2. Run DependencyReference.parse("git/git"). Use jonas/tig or owner/gitit for other cases.
  3. See ValueError: Invalid repository path component: git.

Real repos with these names exist. git/git has 64,288 stars and jonas/tig has 13,379 stars (checked with gh api on 2026-11-13). DependencyReference.parse has 37 call sites in src, including install/package_selection.py and install/validation.py, so apm install and apm.yml entries reach this line.

Expected behavior
Shorthand should behave like the https URL form. https://github.com/git/git already parses on main, because the URL path check has no rstrip.

Proposed fix
Use part.removesuffix(".git") on that line, plus a parametrized test for git, tig, gitit and git.git. It is a one-line change. The 4 new tests fail on main and pass with the fix.

What I checked on a fresh clone of main:

  • A differential run over 115,762 dependency strings found 0 newly rejected inputs, 0 inputs that parse differently and 0 crashes. 7,223 inputs are newly accepted. Each of them was a name made only of ., g, i, t that rstrip had emptied.
  • Against the https URL form as a reference, over 2,728 shorthand and URL pairs, main disagrees on 2,720 and the fix disagrees on 0.
  • ruff check and ruff format --check pass on the 2 changed files.
  • tests/unit/test_generic_git_urls.py gives 213 passed on main and 217 passed with the fix.
  • A wider run of the 116 unit files that call DependencyReference.parse gives 28 failed on both trees with identical failing ids (symlink tests on my Windows machine), and 4,699 passed on main against 4,703 with the fix.
  • Not run: the full suite, the uv CI jobs, the Linux and Windows-compat CI jobs.

Behavior changes the fix would make:

  1. Shorthand names made only of ., g, i, t now parse. This matches what the URL form already does.
  2. owner/..git is still rejected. The message changes from "Invalid repository path component" to the traversal message.
  3. Nothing that parses today is rejected or parsed differently.

Known pre-existing limit, not caused by the fix: on Windows, owner/... gives an install path of apm_modules\owner\.... Win32 drops trailing dots, so that resolves to the owner folder itself. owner/a. collapses to owner\a the same way. The https URL form already accepts these names on main, and shorthand already accepts owner/a.. The fix only lets owner/... through in shorthand as well. I did not check what install, prune or uninstall would do with it, and I did not check whether GitHub allows a repo named .... I am happy to look at that separately if you want.

Environment

  • OS: Windows 11
  • Python Version: 3.14.7
  • APM Version: main at fe6f089 (not a release)
  • VSCode Version: not relevant

Logs

ValueError: Invalid repository path component: git

Additional context
I have the fix and tests ready and will open a PR once a maintainer approves scope here and names a review contact.

Validated with Claude Opus 5.5.

Lingua principale
Python
Stelle
4.3k
Fork
415
Merge medio
3g 4h
PR unite (30g)
176

Preparare l'ambiente

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 microsoft/apm

Tutte le issue di microsoft/apm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.