id_formats: plain-form ids still accept empty parts (follow-up to #432)

Aperta Adatta ai principianti
#587 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
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli

Direzione di ricerca

Leggi pkg/spec/idformat.go e i test di ParseId, usando la riproduzione in source/ come caso iniziale. Fai in modo che la forma semplice rifiuti le barre iniziali, finali e ripetute, mantenendo la forma JSON per le parti vuote. Il lavoro è completato quando questi casi restituiscono un errore utile e i formati validi esistenti superano ancora i test.

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

Descrizione

spec.ParseId still accepts empty segments in plain-form ids, so an incomplete id is sent to the server instead of failing in the CLI. #432 describes the same problem and proposed the fix, but it was closed without a change: pkg/spec/idformat.go on main has no empty-part check.

Repro

list scs_component uses id_formats: ["<source>/<artifact>", "<artifact>"]:

$ harness list scs_component <source_id>/ --debug
POST .../artifacts//components   ->   API error 404: HTTP 404 Not Found

source/ matches the two-part format with artifact="", so the path template renders artifacts//components. The user gets a bare 404 with no hint that the id was incomplete. The same applies to every format that has a fixed part, e.g. <repo>/<pr> with r/.

Proposed fix

As in #432: in the plain form, ParseId rejects a leading /, a trailing / and //, with an error such as id "reg/" has an empty part; pass the parts exactly as a JSON array. The JSON form stays as the escape hatch for genuinely empty parts.

Context

Raised in review of the SCS component commands (#582), and also relevant to the id_formats change in #583.

Lingua principale
Go
Stelle
29
Fork
24
Merge medio
1g 9h
PR unite (30g)
111

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 harness/cli

Tutte le issue di harness/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.