mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* fix spdx namespace and add scheme range assertions Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * validate SPDX document name from source metadata Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * comment why namespace tests only check prefix Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
32 lines
726 B
Go
32 lines
726 B
Go
package spdxhelpers
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
func DocumentName(srcMetadata source.Metadata) (string, error) {
|
|
switch srcMetadata.Scheme {
|
|
case source.ImageScheme:
|
|
return cleanName(srcMetadata.ImageMetadata.UserInput), nil
|
|
case source.DirectoryScheme, source.FileScheme:
|
|
return cleanName(srcMetadata.Path), nil
|
|
}
|
|
|
|
return "", fmt.Errorf("unable to determine document name from scheme=%q", srcMetadata.Scheme)
|
|
}
|
|
|
|
func cleanName(name string) string {
|
|
// remove # according to specification
|
|
name = strings.ReplaceAll(name, "#", "-")
|
|
|
|
// remove : for url construction
|
|
name = strings.ReplaceAll(name, ":", "-")
|
|
|
|
// clean relative pathing
|
|
return path.Clean(name)
|
|
}
|