1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Remove unnecessary URL joins (#676)
Some checks failed
generate-markdown / auto-update-readme (push) Has been cancelled
Go / build (push) Has been cancelled
Go / run_modver (push) Has been cancelled

This should avoid bugs for more complex scenarios.
This commit is contained in:
Paul Schwabauer 2025-09-01 16:13:57 +02:00 committed by GitHub
parent 1a2a8fae9c
commit 187d114631
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 70 deletions

View file

@ -226,18 +226,16 @@ func (d *downloader) download(ctx context.Context, domain string) error {
}
}
base, err := url.Parse(lpmd.URL)
pmdURL, err := url.Parse(lpmd.URL)
if err != nil {
return fmt.Errorf("invalid URL '%s': %v", lpmd.URL, err)
}
base.Path = ""
expr := util.NewPathEval()
if err := d.loadOpenPGPKeys(
client,
lpmd.Document,
base,
expr,
); err != nil {
return err
@ -247,7 +245,7 @@ func (d *downloader) download(ctx context.Context, domain string) error {
client,
expr,
lpmd.Document,
base)
pmdURL)
// Do we need time range based filtering?
if d.cfg.Range != nil {
@ -312,7 +310,6 @@ allFiles:
func (d *downloader) loadOpenPGPKeys(
client util.Client,
doc any,
base *url.URL,
expr *util.PathEval,
) error {
src, err := expr.Eval("$.public_openpgp_keys", doc)
@ -337,7 +334,7 @@ func (d *downloader) loadOpenPGPKeys(
if key.URL == nil {
continue
}
up, err := url.Parse(*key.URL)
u, err := url.Parse(*key.URL)
if err != nil {
slog.Warn("Invalid URL",
"url", *key.URL,
@ -345,9 +342,7 @@ func (d *downloader) loadOpenPGPKeys(
continue
}
u := base.JoinPath(up.Path).String()
res, err := client.Get(u)
res, err := client.Get(u.String())
if err != nil {
slog.Warn(
"Fetching public OpenPGP key failed",