All checks were successful
check / check (push) Successful in 39s
- Add canonical .golangci.yml (v2 schema, default: all, project thresholds for lll/funlen/cyclop/dupl) - Bump golangci-lint pins from v2.0.2 to v2.12.2 in Makefile (go install, new /v2 module path) and Dockerfile (tagged+digest Debian image pin) - Fix all lint findings surfaced by the new linter set across cmd/mfer, internal/bork, internal/cli, internal/log, and mfer: static sentinel errors (err113), context-aware HTTP and exec (noctx), guarded integer conversions and stricter permissions (gosec), named constants (mnd, goconst), function decomposition (funlen, cyclop, gocognit, nestif), declaration ordering (funcorder), t.Parallel/t.TempDir/t.Setenv adoption in tests (paralleltest, usetesting), protobuf getters (protogetter), plus formatting and style cleanups (wsl_v5, nlreturn, lll, revive, testifylint, and others) - Serialize CLI runs in tests behind a mutex so parallel tests do not cross-wire the process-global logger's captured output
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package mfer
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// ManifestURL represents a URL pointing to a manifest file.
|
|
type ManifestURL string
|
|
|
|
// FileURL represents a URL pointing to a file to be fetched.
|
|
type FileURL string
|
|
|
|
// BaseURL represents a base URL for constructing file URLs.
|
|
type BaseURL string
|
|
|
|
// JoinPath safely joins a relative file path to a base URL.
|
|
// The path is properly URL-encoded to prevent path traversal.
|
|
func (b BaseURL) JoinPath(path RelFilePath) (FileURL, error) {
|
|
base, err := url.Parse(string(b))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// Ensure base path ends with /
|
|
if !strings.HasSuffix(base.Path, "/") {
|
|
base.Path += "/"
|
|
}
|
|
|
|
// Encode each path segment individually to preserve slashes
|
|
segments := strings.Split(string(path), "/")
|
|
for i, seg := range segments {
|
|
segments[i] = url.PathEscape(seg)
|
|
}
|
|
|
|
ref, err := url.Parse(strings.Join(segments, "/"))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
resolved := base.ResolveReference(ref)
|
|
|
|
return FileURL(resolved.String()), nil
|
|
}
|
|
|
|
// String returns the URL as a string.
|
|
func (b BaseURL) String() string {
|
|
return string(b)
|
|
}
|
|
|
|
// String returns the URL as a string.
|
|
func (f FileURL) String() string {
|
|
return string(f)
|
|
}
|
|
|
|
// String returns the URL as a string.
|
|
func (m ManifestURL) String() string {
|
|
return string(m)
|
|
}
|