@@ -3,7 +3,6 @@ package techutils
33import (
44 "errors"
55 "fmt"
6- "net/url"
76 "os"
87 "path/filepath"
98 "regexp"
@@ -899,26 +898,20 @@ func ToPackageUrl(compName, version, packageType string, properties ...packageur
899898 if packageType == "" {
900899 packageType = "generic"
901900 }
902- purl := packageurl .NewPackageURL (packageType , "" , compName , version , properties , "" ).String ()
903- // Unescape the output
904- output , err := url .QueryUnescape (purl )
905- if err != nil {
906- log .Debug (fmt .Sprintf ("Failed to unescape package URL: %s" , err ))
907- // Return the original output
908- return purl
901+ // Check if compName contains a namespace
902+ namespace := ""
903+ if lastIndex := strings .LastIndex (compName , "/" ); lastIndex != - 1 {
904+ namespace = compName [:lastIndex ]
905+ compName = compName [lastIndex + 1 :]
909906 }
910- return
907+ return packageurl . NewPackageURL ( packageType , namespace , compName , version , properties , "" ). String ()
911908}
912909
913910func ToPackageRef (compName , version , packageType string ) (output string ) {
914911 if packageType == "" {
915912 packageType = "generic"
916913 }
917- output = fmt .Sprintf ("pkg:%s/%s" , packageType , strings .ReplaceAll (compName , ":" , "/" ))
918- if version != "" {
919- output += fmt .Sprintf ("@%s" , version )
920- }
921- return output
914+ return ToPackageUrl (compName , version , packageType )
922915}
923916
924917// Extract the component name, version and type from PackageUrl and translate it to an Xray component id
0 commit comments