mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Use JoinPath
This avoids issues where parts of the URL are discarded.
This commit is contained in:
parent
cb291bb81b
commit
6ac97810d0
6 changed files with 37 additions and 12 deletions
21
internal/misc/url.go
Normal file
21
internal/misc/url.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// This file is Free Software under the Apache-2.0 License
|
||||
// without warranty, see README.md and LICENSES/Apache-2.0.txt for details.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2025 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
|
||||
// Software-Engineering: 2025 Intevation GmbH <https://intevation.de>
|
||||
|
||||
package misc
|
||||
|
||||
import "net/url"
|
||||
|
||||
// JoinURL joins the two URLs while preserving the query and fragment part of the latter.
|
||||
func JoinURL(baseURL *url.URL, relativeURL *url.URL) *url.URL {
|
||||
u := baseURL.JoinPath(relativeURL.Path)
|
||||
u.RawQuery = relativeURL.RawQuery
|
||||
u.RawFragment = relativeURL.RawFragment
|
||||
// Enforce https, this is required if the base url was only a domain
|
||||
u.Scheme = "https"
|
||||
return u
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue