| 1 | /* |
| 2 | Copyright (c) the purl authors |
| 3 | |
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | of this software and associated documentation files (the "Software"), to deal |
| 6 | in the Software without restriction, including without limitation the rights |
| 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | copies of the Software, and to permit persons to whom the Software is |
| 9 | furnished to do so, subject to the following conditions: |
| 10 | |
| 11 | The above copyright notice and this permission notice shall be included in all |
| 12 | copies or substantial portions of the Software. |
| 13 | |
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | // Package packageurl implements the package-url spec |
| 24 | package packageurlscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/ |
| 25 | |
| 26 | import ( |
| 27 | "errorsscip-go gomod github.com/golang/go/src go1.18 errors/" |
| 28 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 29 | "net/urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/" |
| 30 | "regexpscip-go gomod github.com/golang/go/src go1.18 regexp/" |
| 31 | "slicesscip-go gomod github.com/golang/go/src go1.18 slices/" |
| 32 | "stringsscip-go gomod github.com/golang/go/src go1.18 strings/" |
| 33 | ) |
| 34 | |
| 35 | var ( |
| 36 | // QualifierKeyPattern describes a valid qualifier key: |
| 37 | // |
| 38 | // - The key must be composed only of ASCII letters and numbers, '.', |
| 39 | // '-' and '_' (period, dash and underscore). |
| 40 | // - A key cannot start with a number. |
| 41 | QualifierKeyPatternscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/QualifierKeyPattern. = regexpscip-go gomod github.com/golang/go/src go1.18 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.18 regexp/MustCompile().(`^[A-Za-z\.\-_][0-9A-Za-z\.\-_]*$`) |
| 42 | // TypePattern describes a valid type: |
| 43 | // |
| 44 | // - The type must be composed only of ASCII letters and numbers, '.', |
| 45 | // '+' and '-' (period, plus and dash). |
| 46 | // - A type cannot start with a number. |
| 47 | TypePatternscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePattern. = regexpscip-go gomod github.com/golang/go/src go1.18 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.18 regexp/MustCompile().(`^[A-Za-z\.\-\+][0-9A-Za-z\.\-\+]*$`) |
| 48 | ) |
| 49 | |
| 50 | // These are the known purl types as defined in the spec. Some of these require |
| 51 | // special treatment during parsing. |
| 52 | // https://github.com/package-url/purl-spec#known-purl-types |
| 53 | var ( |
| 54 | // TypeAlpm is a pkg:alpm purl. |
| 55 | TypeAlpmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAlpm. = "alpm" |
| 56 | // TypeApk is a pkg:apk purl. |
| 57 | TypeApkscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApk. = "apk" |
| 58 | // TypeBitbucket is a pkg:bitbucket purl. |
| 59 | TypeBitbucketscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitbucket. = "bitbucket" |
| 60 | // TypeBitnami is a pkg:bitnami purl. |
| 61 | TypeBitnamiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitnami. = "bitnami" |
| 62 | // TypeCargo is a pkg:cargo purl. |
| 63 | TypeCargoscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCargo. = "cargo" |
| 64 | // TypeChromeExtension is a pkg:chrome-extension purl. |
| 65 | TypeChromeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChromeExtension. = "chrome-extension" |
| 66 | // TypeCocoapods is a pkg:cocoapods purl. |
| 67 | TypeCocoapodsscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCocoapods. = "cocoapods" |
| 68 | // TypeComposer is a pkg:composer purl. |
| 69 | TypeComposerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeComposer. = "composer" |
| 70 | // TypeConan is a pkg:conan purl. |
| 71 | TypeConanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeConan. = "conan" |
| 72 | // TypeConda is a pkg:conda purl. |
| 73 | TypeCondascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeConda. = "conda" |
| 74 | // TypeCran is a pkg:cran purl. |
| 75 | TypeCranscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCran. = "cran" |
| 76 | // TypeDebian is a pkg:deb purl. |
| 77 | TypeDebianscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDebian. = "deb" |
| 78 | // TypeDocker is a pkg:docker purl. |
| 79 | TypeDockerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDocker. = "docker" |
| 80 | // TypeGem is a pkg:gem purl. |
| 81 | TypeGemscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGem. = "gem" |
| 82 | // TypeGeneric is a pkg:generic purl. |
| 83 | TypeGenericscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGeneric. = "generic" |
| 84 | // TypeGithub is a pkg:github purl. |
| 85 | TypeGithubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGithub. = "github" |
| 86 | // TypeGolang is a pkg:golang purl. |
| 87 | TypeGolangscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGolang. = "golang" |
| 88 | // TypeHackage is a pkg:hackage purl. |
| 89 | TypeHackagescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHackage. = "hackage" |
| 90 | // TypeHex is a pkg:hex purl. |
| 91 | TypeHexscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHex. = "hex" |
| 92 | // TypeHuggingface is pkg:huggingface purl. |
| 93 | TypeHuggingfacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHuggingface. = "huggingface" |
| 94 | // TypeMLflow is pkg:mlflow purl. |
| 95 | TypeMLFlowscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMLFlow. = "mlflow" |
| 96 | // TypeMaven is a pkg:maven purl. |
| 97 | TypeMavenscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMaven. = "maven" |
| 98 | // TypeNPM is a pkg:npm purl. |
| 99 | TypeNPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNPM. = "npm" |
| 100 | // TypeNuget is a pkg:nuget purl. |
| 101 | TypeNugetscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNuget. = "nuget" |
| 102 | // TypeOCI is a pkg:oci purl. |
| 103 | TypeOCIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOCI. = "oci" |
| 104 | // TypeOTP is a pkg:otp purl. |
| 105 | TypeOTPscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOTP. = "otp" |
| 106 | // TypePub is a pkg:pub purl. |
| 107 | TypePubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePub. = "pub" |
| 108 | // TypePyPi is a pkg:pypi purl. |
| 109 | TypePyPiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePyPi. = "pypi" |
| 110 | // TypeQPKG is a pkg:qpkg purl. |
| 111 | TypeQpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeQpkg. = "qpkg" |
| 112 | // TypeRPM is a pkg:rpm purl. |
| 113 | TypeRPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeRPM. = "rpm" |
| 114 | // TypeSWID is a pkg:swid purl. |
| 115 | TypeSWIDscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSWID. = "swid" |
| 116 | // TypeSwift is a pkg:swift purl. |
| 117 | TypeSwiftscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSwift. = "swift" |
| 118 | // TypeVcpkg is a pkg:vcpkg purl. |
| 119 | TypeVcpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVcpkg. = "vcpkg" |
| 120 | // TypeVSCodeExtension is a pkg:vscode-extension purl. |
| 121 | TypeVSCodeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVSCodeExtension. = "vscode-extension" |
| 122 | // TypeYocto is a pkg:yocto purl. |
| 123 | TypeYoctoscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeYocto. = "yocto" |
| 124 | |
| 125 | // KnownTypes is a map of types that are officially supported by the spec. |
| 126 | // See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#known-purl-types |
| 127 | KnownTypesscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/KnownTypes. = map[string]struct{}{ |
| 128 | TypeAlpmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAlpm.: {}, |
| 129 | TypeApkscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApk.: {}, |
| 130 | TypeBitbucketscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitbucket.: {}, |
| 131 | TypeBitnamiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitnami.: {}, |
| 132 | TypeCargoscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCargo.: {}, |
| 133 | TypeChromeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChromeExtension.: {}, |
| 134 | TypeCocoapodsscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCocoapods.: {}, |
| 135 | TypeComposerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeComposer.: {}, |
| 136 | TypeConanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeConan.: {}, |
| 137 | TypeCondascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeConda.: {}, |
| 138 | TypeCpanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCpan.: {}, |
| 139 | TypeCranscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCran.: {}, |
| 140 | TypeDebianscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDebian.: {}, |
| 141 | TypeDockerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDocker.: {}, |
| 142 | TypeGemscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGem.: {}, |
| 143 | TypeGenericscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGeneric.: {}, |
| 144 | TypeGithubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGithub.: {}, |
| 145 | TypeGolangscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGolang.: {}, |
| 146 | TypeHackagescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHackage.: {}, |
| 147 | TypeHexscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHex.: {}, |
| 148 | TypeHuggingfacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHuggingface.: {}, |
| 149 | TypeMavenscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMaven.: {}, |
| 150 | TypeMLFlowscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMLFlow.: {}, |
| 151 | TypeNPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNPM.: {}, |
| 152 | TypeNugetscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNuget.: {}, |
| 153 | TypeOCIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOCI.: {}, |
| 154 | TypeOTPscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOTP.: {}, |
| 155 | TypePubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePub.: {}, |
| 156 | TypePyPiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePyPi.: {}, |
| 157 | TypeQpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeQpkg.: {}, |
| 158 | TypeRPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeRPM.: {}, |
| 159 | TypeSWIDscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSWID.: {}, |
| 160 | TypeSwiftscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSwift.: {}, |
| 161 | TypeVcpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVcpkg.: {}, |
| 162 | TypeVSCodeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVSCodeExtension.: {}, |
| 163 | TypeYoctoscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeYocto.: {}, |
| 164 | } |
| 165 | |
| 166 | TypeApachescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApache. = "apache" |
| 167 | TypeAndroidscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAndroid. = "android" |
| 168 | TypeAtomscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAtom. = "atom" |
| 169 | TypeBowerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBower. = "bower" |
| 170 | TypeBrewscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBrew. = "brew" |
| 171 | TypeBuildrootscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBuildroot. = "buildroot" |
| 172 | TypeCarthagescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCarthage. = "carthage" |
| 173 | TypeChefscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChef. = "chef" |
| 174 | TypeChocolateyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChocolatey. = "chocolatey" |
| 175 | TypeClojarsscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeClojars. = "clojars" |
| 176 | TypeCoreosscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCoreos. = "coreos" |
| 177 | TypeCpanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCpan. = "cpan" |
| 178 | TypeCtanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCtan. = "ctan" |
| 179 | TypeCrystalscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCrystal. = "crystal" |
| 180 | TypeDrupalscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDrupal. = "drupal" |
| 181 | TypeDtypescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDtype. = "dtype" |
| 182 | TypeDubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDub. = "dub" |
| 183 | TypeElmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeElm. = "elm" |
| 184 | TypeEclipsescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeEclipse. = "eclipse" |
| 185 | TypeGiteascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGitea. = "gitea" |
| 186 | TypeGitlabscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGitlab. = "gitlab" |
| 187 | TypeGradlescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGradle. = "gradle" |
| 188 | TypeGuixscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGuix. = "guix" |
| 189 | TypeHaxescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHaxe. = "haxe" |
| 190 | TypeHelmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHelm. = "helm" |
| 191 | TypeJuliascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeJulia. = "julia" |
| 192 | TypeLuascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeLua. = "lua" |
| 193 | TypeMelpascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMelpa. = "melpa" |
| 194 | TypeMeteorscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMeteor. = "meteor" |
| 195 | TypeNimscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNim. = "nim" |
| 196 | TypeNixscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNix. = "nix" |
| 197 | TypeOpamscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOpam. = "opam" |
| 198 | TypeOpenwrtscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOpenwrt. = "openwrt" |
| 199 | TypeOsgiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOsgi. = "osgi" |
| 200 | TypeP2scip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeP2. = "p2" |
| 201 | TypePearscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePear. = "pear" |
| 202 | TypePeclscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePecl. = "pecl" |
| 203 | TypePERL6scip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePERL6. = "perl6" |
| 204 | TypePlatformioscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePlatformio. = "platformio" |
| 205 | TypeEbuildscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeEbuild. = "ebuild" |
| 206 | TypePuppetscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePuppet. = "puppet" |
| 207 | TypeSourceforgescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSourceforge. = "sourceforge" |
| 208 | TypeSublimescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSublime. = "sublime" |
| 209 | TypeTerraformscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeTerraform. = "terraform" |
| 210 | TypeVagrantscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVagrant. = "vagrant" |
| 211 | TypeVimscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVim. = "vim" |
| 212 | TypeWORDPRESSscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeWORDPRESS. = "wordpress" |
| 213 | |
| 214 | // CandidateTypes is a map of types that are not yet officially supported by the spec, |
| 215 | // but are being considered for inclusion. |
| 216 | // See https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#other-candidate-types-to-define |
| 217 | CandidateTypesscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/CandidateTypes. = map[string]struct{}{ |
| 218 | TypeApachescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApache.: {}, |
| 219 | TypeAndroidscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAndroid.: {}, |
| 220 | TypeAtomscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAtom.: {}, |
| 221 | TypeBowerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBower.: {}, |
| 222 | TypeBrewscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBrew.: {}, |
| 223 | TypeBuildrootscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBuildroot.: {}, |
| 224 | TypeCarthagescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCarthage.: {}, |
| 225 | TypeChefscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChef.: {}, |
| 226 | TypeChocolateyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChocolatey.: {}, |
| 227 | TypeClojarsscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeClojars.: {}, |
| 228 | TypeCoreosscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCoreos.: {}, |
| 229 | TypeCtanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCtan.: {}, |
| 230 | TypeCrystalscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCrystal.: {}, |
| 231 | TypeDrupalscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDrupal.: {}, |
| 232 | TypeDtypescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDtype.: {}, |
| 233 | TypeDubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDub.: {}, |
| 234 | TypeElmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeElm.: {}, |
| 235 | TypeEclipsescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeEclipse.: {}, |
| 236 | TypeGiteascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGitea.: {}, |
| 237 | TypeGitlabscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGitlab.: {}, |
| 238 | TypeGradlescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGradle.: {}, |
| 239 | TypeGuixscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGuix.: {}, |
| 240 | TypeHaxescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHaxe.: {}, |
| 241 | TypeHelmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHelm.: {}, |
| 242 | TypeJuliascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeJulia.: {}, |
| 243 | TypeLuascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeLua.: {}, |
| 244 | TypeMelpascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMelpa.: {}, |
| 245 | TypeMeteorscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMeteor.: {}, |
| 246 | TypeNimscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNim.: {}, |
| 247 | TypeNixscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNix.: {}, |
| 248 | TypeOpamscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOpam.: {}, |
| 249 | TypeOpenwrtscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOpenwrt.: {}, |
| 250 | TypeOsgiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOsgi.: {}, |
| 251 | TypeP2scip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeP2.: {}, |
| 252 | TypePearscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePear.: {}, |
| 253 | TypePeclscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePecl.: {}, |
| 254 | TypePERL6scip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePERL6.: {}, |
| 255 | TypePlatformioscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePlatformio.: {}, |
| 256 | TypeEbuildscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeEbuild.: {}, |
| 257 | TypePuppetscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePuppet.: {}, |
| 258 | TypeSourceforgescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSourceforge.: {}, |
| 259 | TypeSublimescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSublime.: {}, |
| 260 | TypeTerraformscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeTerraform.: {}, |
| 261 | TypeVagrantscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVagrant.: {}, |
| 262 | TypeVimscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVim.: {}, |
| 263 | TypeWORDPRESSscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeWORDPRESS.: {}, |
| 264 | TypeYoctoscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeYocto.: {}, |
| 265 | } |
| 266 | ) |
| 267 | |
| 268 | // Qualifier represents a single key=value qualifier in the package url |
| 269 | type Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier# struct { |
| 270 | Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key. string |
| 271 | Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value. string |
| 272 | } |
| 273 | |
| 274 | // String returns a canonical string representation of the qualifier according to [SPEC]. |
| 275 | // |
| 276 | // [SPEC] https://github.com/package-url/purl-spec/blob/main/PURL-SPECIFICATION.rst#rules-for-each-purl-component |
| 277 | func (q Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#) Stringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#String().() string { |
| 278 | // A value must be a percent-encoded string |
| 279 | var b stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder# |
| 280 | escapeQualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeQualifier().(&b, q.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) |
| 281 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('=') |
| 282 | escapeQualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeQualifier().(&b, q.Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value.) |
| 283 | return b.Stringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#String().() |
| 284 | } |
| 285 | |
| 286 | // Qualifiers is a slice of key=value pairs, with order preserved as it appears |
| 287 | // in the package URL. |
| 288 | type Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers# []Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier# |
| 289 | |
| 290 | // String returns a canonical string representation of the qualifiers as keys + values. |
| 291 | // Canonical form requires qualifier keys to be lexicographically ordered. |
| 292 | // The leading `?` qualifier component delimiter is excluded. |
| 293 | func (q Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#) Stringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#String().() string { |
| 294 | if len(q) == 0 { |
| 295 | return "" |
| 296 | } |
| 297 | slicesscip-go gomod github.com/golang/go/src go1.18 slices/.SortFuncscip-go gomod github.com/golang/go/src go1.18 slices/SortFunc().(q, func(a, b Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#) int { return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Comparescip-go gomod github.com/golang/go/src go1.18 strings/Compare().(a.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key., b.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) }) |
| 298 | var b stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder# |
| 299 | // Estimate capacity: each qualifier needs key + "=" + value + "&" |
| 300 | b.Growscip-go gomod github.com/golang/go/src go1.18 strings/Builder#Grow().(len(q) * 32) |
| 301 | for i, qq := range q { |
| 302 | if i > 0 { |
| 303 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('&') |
| 304 | } |
| 305 | escapeQualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeQualifier().(&b, qq.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) |
| 306 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('=') |
| 307 | escapeQualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeQualifier().(&b, qq.Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value.) |
| 308 | } |
| 309 | return b.Stringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#String().() |
| 310 | } |
| 311 | |
| 312 | // escapeQualifier escapes a qualifier key or value for use in the query string. |
| 313 | // Per purl spec, ':' is NOT encoded but most other special characters are. |
| 314 | func escapeQualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeQualifier().(b *stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder#, s string) { |
| 315 | for i := 0; i < len(s); i++ { |
| 316 | c := s[i] |
| 317 | if isQualifierSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isQualifierSafe().(c) { |
| 318 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().(c) |
| 319 | } else { |
| 320 | writePercentEncodedBytescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedByte().(b, c) |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // isQualifierSafe reports whether c can appear unencoded in a purl qualifier. |
| 326 | // Per purl spec, ':' is allowed unencoded in qualifier values. |
| 327 | func isQualifierSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isQualifierSafe().(c byte) bool { |
| 328 | // Standard unreserved characters plus ':' |
| 329 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || |
| 330 | c == '-' || c == '.' || c == '_' || c == '~' || c == ':' |
| 331 | } |
| 332 | |
| 333 | // QualifiersFromMap constructs a Qualifiers slice from a string map. To get a |
| 334 | // deterministic qualifier order (despite maps not providing any iteration order |
| 335 | // guarantees) the returned Qualifiers are sorted in increasing order of key. |
| 336 | func QualifiersFromMapscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/QualifiersFromMap().(mm map[string]string) Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers# { |
| 337 | q := make(Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#, 0, len(mm)) |
| 338 | |
| 339 | for k, v := range mm { |
| 340 | q = append(q, Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#{Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.: k, Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value.: v}) |
| 341 | } |
| 342 | |
| 343 | // sort for deterministic qualifier order |
| 344 | slicesscip-go gomod github.com/golang/go/src go1.18 slices/.SortFuncscip-go gomod github.com/golang/go/src go1.18 slices/SortFunc().(q, func(a, b Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#) int { return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Comparescip-go gomod github.com/golang/go/src go1.18 strings/Compare().(a.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key., b.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) }) |
| 345 | |
| 346 | return q |
| 347 | } |
| 348 | |
| 349 | // Map converts a Qualifiers struct to a string map. |
| 350 | func (qq Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#) Mapscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#Map().() map[string]string { |
| 351 | m := make(map[string]string) |
| 352 | |
| 353 | for i := 0; i < len(qq); i++ { |
| 354 | k := qq[i].Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key. |
| 355 | v := qq[i].Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value. |
| 356 | m[k] = v |
| 357 | } |
| 358 | |
| 359 | return m |
| 360 | } |
| 361 | |
| 362 | func (qq *Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#) Normalizescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#Normalize().() error { |
| 363 | qs := *qq |
| 364 | normedQQ := make(Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#, 0, len(qs)) |
| 365 | for _, q := range qs { |
| 366 | if q.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key. == "" { |
| 367 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("key is missing from qualifier: %v", q) |
| 368 | } |
| 369 | if q.Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value. == "" { |
| 370 | // Empty values are equivalent to the key being omitted from the PackageURL. |
| 371 | continue |
| 372 | } |
| 373 | key := toLowerASCIIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/toLowerASCII().(q.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) |
| 374 | if !validQualifierKeyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validQualifierKey().(key) { |
| 375 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid qualifier key: %q", key) |
| 376 | } |
| 377 | normedQQ = append(normedQQ, Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#{key, q.Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value.}) |
| 378 | } |
| 379 | slicesscip-go gomod github.com/golang/go/src go1.18 slices/.SortFuncscip-go gomod github.com/golang/go/src go1.18 slices/SortFunc().(normedQQ, func(a, b Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#) int { return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Comparescip-go gomod github.com/golang/go/src go1.18 strings/Compare().(a.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key., b.Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) }) |
| 380 | for i := 1; i < len(normedQQ); i++ { |
| 381 | if normedQQ[i-1].Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key. == normedQQ[i].Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key. { |
| 382 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("duplicate qualifier key: %q", normedQQ[i].Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.) |
| 383 | } |
| 384 | } |
| 385 | *qq = normedQQ |
| 386 | return nil |
| 387 | } |
| 388 | |
| 389 | // toLowerASCII returns s with all ASCII uppercase letters converted to lowercase. |
| 390 | // It avoids allocation if s is already lowercase. |
| 391 | func toLowerASCIIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/toLowerASCII().(s string) string { |
| 392 | needsConvert := -1 |
| 393 | for i := 0; i < len(s); i++ { |
| 394 | if c := s[i]; c >= 'A' && c <= 'Z' { |
| 395 | needsConvert = i |
| 396 | break |
| 397 | } |
| 398 | } |
| 399 | if needsConvert < 0 { |
| 400 | return s |
| 401 | } |
| 402 | |
| 403 | b := make([]byte, len(s)) |
| 404 | copy(b, s[:needsConvert]) |
| 405 | for i := needsConvert; i < len(s); i++ { |
| 406 | c := s[i] |
| 407 | if c >= 'A' && c <= 'Z' { |
| 408 | c += 32 |
| 409 | } |
| 410 | b[i] = c |
| 411 | } |
| 412 | return string(b) |
| 413 | } |
| 414 | |
| 415 | // PackageURL is the struct representation of the parts that make a package url |
| 416 | type PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL# struct { |
| 417 | Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type. string |
| 418 | Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. string |
| 419 | Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name. string |
| 420 | Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version. string |
| 421 | Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers. Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers# |
| 422 | Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath. string |
| 423 | } |
| 424 | |
| 425 | // NewPackageURL creates a new PackageURL struct instance based on input |
| 426 | func NewPackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/NewPackageURL().(purlType, namespace, name, version string, |
| 427 | qualifiers Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#, subpath string) *PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL# { |
| 428 | |
| 429 | return &PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{ |
| 430 | Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.: purlType, |
| 431 | Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.: namespace, |
| 432 | Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.: name, |
| 433 | Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.: version, |
| 434 | Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers.: qualifiers, |
| 435 | Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.: subpath, |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // ToString returns a canonical string representation of the qualifier according to [SPEC]. |
| 440 | // |
| 441 | // [SPEC] https://github.com/package-url/purl-spec/blob/main/PURL-SPECIFICATION.rst#rules-for-each-purl-component |
| 442 | func (p *PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#) ToStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#ToString().() string { |
| 443 | var b stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder# |
| 444 | // Estimate capacity for typical purl, including component delimiters. |
| 445 | b.Growscip-go gomod github.com/golang/go/src go1.18 strings/Builder#Grow().(4 + len(p.Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.) + 1 + len(p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.) + 1 + len(p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.) + 1 + len(p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.) + len(p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.) + 32) |
| 446 | |
| 447 | b.WriteStringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteString().("pkg:") |
| 448 | b.WriteStringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteString().(p.Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.) |
| 449 | |
| 450 | // Each namespace segment shall be a percent-encoded string. |
| 451 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. != "" { |
| 452 | start := 0 |
| 453 | for i := 0; i <= len(p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.); i++ { |
| 454 | if i == len(p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.) || p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.[i] == '/' { |
| 455 | if i > start { |
| 456 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('/') |
| 457 | writePercentEncodedStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedString().(&b, p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.[start:i]) |
| 458 | } |
| 459 | start = i + 1 |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | // A name shall be a percent-encoded string. |
| 465 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('/') |
| 466 | writePercentEncodedStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedString().(&b, p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.) |
| 467 | |
| 468 | if p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version. != "" { |
| 469 | // A version shall be a percent-encoded string. |
| 470 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('@') |
| 471 | writePercentEncodedStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedString().(&b, p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.) |
| 472 | } |
| 473 | |
| 474 | if len(p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers.) > 0 { |
| 475 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('?') |
| 476 | b.WriteStringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteString().(p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers..Stringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#String().()) |
| 477 | } |
| 478 | |
| 479 | // Each subpath segment shall be a percent-encoded string. |
| 480 | if p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath. != "" { |
| 481 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('#') |
| 482 | escapeSubpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeSubpath().(&b, p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.) |
| 483 | } |
| 484 | |
| 485 | return b.Stringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#String().() |
| 486 | } |
| 487 | |
| 488 | func (p PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#) Stringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#String().() string { |
| 489 | return p.ToStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#ToString().() |
| 490 | } |
| 491 | |
| 492 | // FromString parses a valid package url string into a [PackageURL]. |
| 493 | func FromStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/FromString().(purl string) (PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#, error) { |
| 494 | // Check scheme |
| 495 | if len(purl) < 4 || toLowerASCIIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/toLowerASCII().(purl[:4]) != "pkg:" { |
| 496 | return PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{}, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("purl scheme is not \"pkg\": %q", purl) |
| 497 | } |
| 498 | |
| 499 | remainder := purl[4:] |
| 500 | |
| 501 | // Handle pkg:/ and pkg:// formats by stripping leading slashes |
| 502 | for len(remainder) > 0 && remainder[0] == '/' { |
| 503 | remainder = remainder[1:] |
| 504 | } |
| 505 | |
| 506 | // Extract fragment (subpath) |
| 507 | var subpath string |
| 508 | if idx := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.18 strings/IndexByte().(remainder, '#'); idx != -1 { |
| 509 | // A subpath is a percent-encoded string and must be decoded like the |
| 510 | // other components (namespace, name, version). |
| 511 | decoded, err := percentDecodeSubpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecodeSubpath().(remainder[idx+1:]) |
| 512 | if err != nil { |
| 513 | return PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{}, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("error unescaping subpath: %w", err) |
| 514 | } |
| 515 | subpath = decoded |
| 516 | remainder = remainder[:idx] |
| 517 | } |
| 518 | |
| 519 | // Extract query string (qualifiers) |
| 520 | var rawQuery string |
| 521 | if idx := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.18 strings/IndexByte().(remainder, '?'); idx != -1 { |
| 522 | rawQuery = remainder[idx+1:] |
| 523 | remainder = remainder[:idx] |
| 524 | } |
| 525 | |
| 526 | // Extract type |
| 527 | typ, remainder, ok := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Cutscip-go gomod github.com/golang/go/src go1.18 strings/Cut().(remainder, "/") |
| 528 | if !ok { |
| 529 | return PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{}, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("purl is missing type or name") |
| 530 | } |
| 531 | typ = toLowerASCIIscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/toLowerASCII().(typ) |
| 532 | |
| 533 | // Parse qualifiers |
| 534 | qualifiers, err := parseQualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/parseQualifiers().(rawQuery) |
| 535 | if err != nil { |
| 536 | return PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{}, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid qualifiers: %w", err) |
| 537 | } |
| 538 | |
| 539 | // Parse namespace, name, version |
| 540 | namespace, name, version, err := separateNamespaceNameVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/separateNamespaceNameVersion().(typ, remainder) |
| 541 | if err != nil { |
| 542 | return PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{}, err |
| 543 | } |
| 544 | |
| 545 | pURL := PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{ |
| 546 | Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers.: qualifiers, |
| 547 | Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.: typ, |
| 548 | Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.: namespace, |
| 549 | Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.: name, |
| 550 | Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.: version, |
| 551 | Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.: subpath, |
| 552 | } |
| 553 | |
| 554 | err = pURL.Normalizescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Normalize().() |
| 555 | return pURL, err |
| 556 | } |
| 557 | |
| 558 | // Normalize converts p to its canonical form, returning an error if p is invalid. |
| 559 | func (p *PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#) Normalizescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Normalize().() error { |
| 560 | typ := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(p.Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.) |
| 561 | if !validTypescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validType().(typ) { |
| 562 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid type %q", typ) |
| 563 | } |
| 564 | namespace := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Trimscip-go gomod github.com/golang/go/src go1.18 strings/Trim().(p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace., "/") |
| 565 | if err := p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers..Normalizescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#Normalize().(); err != nil { |
| 566 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid qualifiers: %v", err) |
| 567 | } |
| 568 | if p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name. == "" { |
| 569 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("purl is missing name") |
| 570 | } |
| 571 | subpath := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Trimscip-go gomod github.com/golang/go/src go1.18 strings/Trim().(p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath., "/") |
| 572 | segs := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Splitscip-go gomod github.com/golang/go/src go1.18 strings/Split().(p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath., "/") |
| 573 | for i, s := range segs { |
| 574 | if (s == "." || s == "..") && i != 0 { |
| 575 | return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid Package URL subpath: %q", p.Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.) |
| 576 | } |
| 577 | } |
| 578 | *p = PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#{ |
| 579 | Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type.: typ, |
| 580 | Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.: typeAdjustNamespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustNamespace().(typ, namespace), |
| 581 | Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.: typeAdjustNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustName().(typ, p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name., p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers.), |
| 582 | Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.: typeAdjustVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustVersion().(typ, p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.), |
| 583 | Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers.: p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers., |
| 584 | Subpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Subpath.: subpath, |
| 585 | } |
| 586 | return validCustomRulesscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validCustomRules().(*p) |
| 587 | } |
| 588 | |
| 589 | // percentDecode percent-decodes a purl component according to [Encoding]. |
| 590 | // |
| 591 | // [Encoding] https://github.com/package-url/purl-spec/blob/main/PURL-SPECIFICATION.rst#character-encoding |
| 592 | func percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(s string) (string, error) { |
| 593 | // Note: uses [url.PathUnescape] instead of [url.QueryUnescape] to treat '+' characters |
| 594 | // literally (not as space). |
| 595 | return urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.PathUnescapescip-go gomod github.com/golang/go/src go1.18 `net/url`/PathUnescape().(s) |
| 596 | } |
| 597 | |
| 598 | // percentDecodeSubpath percent-decodes a subpath by decoding each '/'-separated |
| 599 | // segment on its own, so an encoded slash inside a segment is not treated as a |
| 600 | // segment separator. This mirrors the per-segment decoding done for the namespace. |
| 601 | func percentDecodeSubpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecodeSubpath().(s string) (string, error) { |
| 602 | if !stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(s, "%") { |
| 603 | return s, nil |
| 604 | } |
| 605 | segments := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Splitscip-go gomod github.com/golang/go/src go1.18 strings/Split().(s, "/") |
| 606 | for i, segment := range segments { |
| 607 | decoded, err := percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(segment) |
| 608 | if err != nil { |
| 609 | return "", err |
| 610 | } |
| 611 | segments[i] = decoded |
| 612 | } |
| 613 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Joinscip-go gomod github.com/golang/go/src go1.18 strings/Join().(segments, "/"), nil |
| 614 | } |
| 615 | |
| 616 | // writePercentEncodedString percent-encodes s as a purl path segment and writes it to the builder. |
| 617 | func writePercentEncodedStringscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedString().(b *stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder#, s string) { |
| 618 | // Check if we need to escape at all |
| 619 | needsEscape := false |
| 620 | for i := 0; i < len(s); i++ { |
| 621 | if !isPathSegmentSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isPathSegmentSafe().(s[i]) { |
| 622 | needsEscape = true |
| 623 | break |
| 624 | } |
| 625 | } |
| 626 | if !needsEscape { |
| 627 | b.WriteStringscip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteString().(s) |
| 628 | return |
| 629 | } |
| 630 | |
| 631 | // Need to escape - process character by character |
| 632 | for i := 0; i < len(s); i++ { |
| 633 | c := s[i] |
| 634 | if isPathSegmentSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isPathSegmentSafe().(c) { |
| 635 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().(c) |
| 636 | } else { |
| 637 | writePercentEncodedBytescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedByte().(b, c) |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | // writePercentEncodedByte percent-encodes the given byte as per [RFC-3986] and writes the result to |
| 643 | // the supplied [strings.Builder]. |
| 644 | // |
| 645 | // [RFC-3986]: https://datatracker.ietf.org/doc/html/rfc3986#page-12 |
| 646 | func writePercentEncodedBytescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedByte().(b *stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder#, c byte) { |
| 647 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('%') |
| 648 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().(hexUpperscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/hexUpper.[c>>4]) |
| 649 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().(hexUpperscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/hexUpper.[c&0x0f]) |
| 650 | } |
| 651 | |
| 652 | // isPathSegmentSafe reports whether c can appear unencoded in a purl path segment. |
| 653 | // Per the purl spec, the only characters that must NOT be percent-encoded are: |
| 654 | // alphanumerics, the unreserved punctuation '-', '.', '_', '~', and ':'. |
| 655 | // All other characters — including RFC 3986 sub-delimiters such as '(', ')', '!', |
| 656 | // '$', '&', "'", '*', ',', ';', '=' — must be percent-encoded. |
| 657 | // |
| 658 | // See https://ecma-tc54.github.io/ECMA-427/#sec-purl-specification-character-encoding |
| 659 | func isPathSegmentSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isPathSegmentSafe().(c byte) bool { |
| 660 | return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || |
| 661 | c == '-' || c == '.' || c == '_' || c == '~' || c == ':' |
| 662 | } |
| 663 | |
| 664 | // escapeSubpath escapes a subpath, handling segments separated by '/'. |
| 665 | func escapeSubpathscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/escapeSubpath().(b *stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Builderscip-go gomod github.com/golang/go/src go1.18 strings/Builder#, s string) { |
| 666 | for i := 0; i < len(s); i++ { |
| 667 | c := s[i] |
| 668 | if c == '/' { |
| 669 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().('/') |
| 670 | } else if isPathSegmentSafescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/isPathSegmentSafe().(c) { |
| 671 | b.WriteBytescip-go gomod github.com/golang/go/src go1.18 strings/Builder#WriteByte().(c) |
| 672 | } else { |
| 673 | writePercentEncodedBytescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/writePercentEncodedByte().(b, c) |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | const hexUpperscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/hexUpper. = "0123456789ABCDEF" |
| 679 | |
| 680 | // separateNamespaceNameVersion parses the <namespace>/<name>@<version> part of a purl (the |
| 681 | // remainder parameter) into its constituent components. It aims to follow the [HOW-TO-PARSE] |
| 682 | // procedure. |
| 683 | // |
| 684 | // [HOW-TO-PARSE]: https://github.com/package-url/purl-spec/blob/main/docs/how-to-parse.md |
| 685 | func separateNamespaceNameVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/separateNamespaceNameVersion().(purlType string, remainder string) (ns, name, version string, err error) { |
| 686 | // NPM purls can have a namespace ("scope") that starts with an '@' character. |
| 687 | // For example, "pkg:npm/@babel/core". |
| 688 | // For any other purl type this indicates malformed purl input. |
| 689 | if purlType != TypeNPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNPM. && stringsscip-go gomod github.com/golang/go/src go1.18 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.18 strings/HasPrefix().(remainder, "@") { |
| 690 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("purl is missing name") |
| 691 | } |
| 692 | // A leading '@' is only valid for npm when it introduces a scope, which |
| 693 | // requires a '/' to separate the scope from the name (for example, |
| 694 | // "pkg:npm/@babel/core"). A remainder like "@4.17.21" has no '/', so it is a |
| 695 | // bare scope with no name and must be rejected the same way as v0.1.3 did. |
| 696 | if purlType == TypeNPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeNPM. && stringsscip-go gomod github.com/golang/go/src go1.18 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.18 strings/HasPrefix().(remainder, "@") && !stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(remainder, "/") { |
| 697 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("purl is missing name") |
| 698 | } |
| 699 | |
| 700 | // Split the remainder once from right on '@'. |
| 701 | // The left side is the remainder. |
| 702 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.LastIndexscip-go gomod github.com/golang/go/src go1.18 strings/LastIndex().(remainder, "@") > 0 { |
| 703 | remainder, version = rightmostSplitscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/rightmostSplit().(remainder, "@") |
| 704 | // Percent-decode the right side. This is the version. |
| 705 | version, err = percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(version) |
| 706 | if err != nil { |
| 707 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("error unescaping version: %w", err) |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // Split this once from right on '/'. |
| 712 | // The left side is the remainder. |
| 713 | remainder, name = rightmostSplitscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/rightmostSplit().(remainder, "/") |
| 714 | // Percent-decode the right side. This is the name. |
| 715 | name, err = percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(name) |
| 716 | if err != nil { |
| 717 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("error unescaping name: %w", err) |
| 718 | } |
| 719 | |
| 720 | // Split the remainder on '/'. |
| 721 | segments := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Splitscip-go gomod github.com/golang/go/src go1.18 strings/Split().(remainder, "/") |
| 722 | nsSegments := []string{} |
| 723 | for _, segment := range segments { |
| 724 | // Discard any empty segment from that split. |
| 725 | if segment == "" { |
| 726 | continue |
| 727 | } |
| 728 | // Percent-decode each segment. |
| 729 | nsSegment, err := percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(segment) |
| 730 | if err != nil { |
| 731 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("error unescaping namespace: %w", err) |
| 732 | } |
| 733 | nsSegments = append(nsSegments, nsSegment) |
| 734 | } |
| 735 | // Join segments back with a '/'. |
| 736 | ns = stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Joinscip-go gomod github.com/golang/go/src go1.18 strings/Join().(nsSegments, "/") |
| 737 | |
| 738 | if name == "" { |
| 739 | return "", "", "", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("purl is missing name") |
| 740 | } |
| 741 | |
| 742 | return ns, name, version, nil |
| 743 | } |
| 744 | |
| 745 | // rightmostSplit splits the input path on a given delimiter such that the lhs returns the string to |
| 746 | // the left of the right-most delimiter and rhs return the string to the right of the right-most |
| 747 | // delimiter. For example, given path "github.com/package-url/packageurl-go" and delimiter "/" the |
| 748 | // lhs will be "github.com/package-url" and rhs will be "packageurl-go". |
| 749 | func rightmostSplitscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/rightmostSplit().(path string, delim string) (lhs, rhs string) { |
| 750 | lastSepIdx := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.LastIndexscip-go gomod github.com/golang/go/src go1.18 strings/LastIndex().(path, delim) |
| 751 | rhs = path[lastSepIdx+1:] |
| 752 | if lastSepIdx >= 0 { |
| 753 | lhs = path[:lastSepIdx] |
| 754 | } |
| 755 | return lhs, rhs |
| 756 | } |
| 757 | |
| 758 | func parseQualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/parseQualifiers().(rawQuery string) (Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#, error) { |
| 759 | // we need to parse the qualifiers ourselves and cannot rely on the `url.Query` type because |
| 760 | // that uses a map, meaning it's unordered. We want to keep the order of the qualifiers, so this |
| 761 | // function re-implements the `url.parseQuery` function based on our `Qualifier` type. Most of |
| 762 | // the code here is taken from `url.parseQuery`. |
| 763 | q := Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#{} |
| 764 | for rawQuery != "" { |
| 765 | var key string |
| 766 | key, rawQuery, _ = stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Cutscip-go gomod github.com/golang/go/src go1.18 strings/Cut().(rawQuery, "&") |
| 767 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(key, ";") { |
| 768 | return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid semicolon separator in query") |
| 769 | } |
| 770 | if key == "" { |
| 771 | continue |
| 772 | } |
| 773 | // The key is the lowercase left side. |
| 774 | key, value, _ := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Cutscip-go gomod github.com/golang/go/src go1.18 strings/Cut().(key, "=") |
| 775 | key = stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(key) |
| 776 | |
| 777 | if !validQualifierKeyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validQualifierKey().(key) { |
| 778 | return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("invalid qualifier key: '%s'", key) |
| 779 | } |
| 780 | |
| 781 | // The value is the percent-decoded right side. |
| 782 | value, err := percentDecodescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/percentDecode().(value) |
| 783 | if err != nil { |
| 784 | return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("error unescaping qualifier value %q", value) |
| 785 | } |
| 786 | |
| 787 | q = append(q, Qualifierscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#{Keyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Key.: key, Valuescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifier#Value.: value}) |
| 788 | } |
| 789 | return q, nil |
| 790 | } |
| 791 | |
| 792 | // Make any purl type-specific adjustments to the parsed namespace. |
| 793 | // See https://github.com/package-url/purl-spec#known-purl-types |
| 794 | func typeAdjustNamespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustNamespace().(purlType, ns string) string { |
| 795 | switch purlType { |
| 796 | case TypeAlpmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAlpm., |
| 797 | TypeApkscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApk., |
| 798 | TypeBitbucketscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitbucket., |
| 799 | TypeBrewscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBrew., |
| 800 | TypeComposerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeComposer., |
| 801 | TypeDebianscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDebian., |
| 802 | TypeGithubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGithub., |
| 803 | TypeGolangscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGolang., |
| 804 | TypeRPMscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeRPM., |
| 805 | TypeQpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeQpkg.: |
| 806 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(ns) |
| 807 | } |
| 808 | return ns |
| 809 | } |
| 810 | |
| 811 | // Make any purl type-specific adjustments to the parsed name. |
| 812 | // See https://github.com/package-url/purl-spec#known-purl-types |
| 813 | func typeAdjustNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustName().(purlType, name string, qualifiers Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#) string { |
| 814 | quals := qualifiers.Mapscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#Map().() |
| 815 | switch purlType { |
| 816 | case TypeAlpmscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeAlpm., |
| 817 | TypeApkscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeApk., |
| 818 | TypeBitbucketscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitbucket., |
| 819 | TypeBitnamiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBitnami., |
| 820 | TypeBrewscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeBrew., |
| 821 | TypeChromeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChromeExtension., |
| 822 | TypeComposerscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeComposer., |
| 823 | TypeDebianscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeDebian., |
| 824 | TypeGithubscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGithub., |
| 825 | TypeGolangscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeGolang.: |
| 826 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(name) |
| 827 | case TypePyPiscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypePyPi.: |
| 828 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.18 strings/ReplaceAll().(name, "_", "-")) |
| 829 | case TypeMLFlowscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeMLFlow.: |
| 830 | return adjustMlflowNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/adjustMlflowName().(name, quals) |
| 831 | } |
| 832 | return name |
| 833 | } |
| 834 | |
| 835 | // Make any purl type-specific adjustments to the parsed version. |
| 836 | // See https://github.com/package-url/purl-spec#known-purl-types |
| 837 | func typeAdjustVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/typeAdjustVersion().(purlType, version string) string { |
| 838 | switch purlType { |
| 839 | case TypeHuggingfacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeHuggingface.: |
| 840 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(version) |
| 841 | } |
| 842 | return version |
| 843 | } |
| 844 | |
| 845 | // https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#mlflow |
| 846 | func adjustMlflowNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/adjustMlflowName().(name string, qualifiers map[string]string) string { |
| 847 | if repo, ok := qualifiers["repository_url"]; ok { |
| 848 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(repo, "databricks") { |
| 849 | // Databricks is case-insensitive and must be lowercased |
| 850 | return stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.18 strings/ToLower().(name) |
| 851 | } |
| 852 | |
| 853 | // Azure ML is case-sensitive and must be kept as-is |
| 854 | // Unknown repository type, keep as-is |
| 855 | return name |
| 856 | |
| 857 | } else { |
| 858 | // No repository qualifier given, keep as-is |
| 859 | return name |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // validQualifierKey validates a qualifierKey against our QualifierKeyPattern. |
| 864 | // The key must be composed only of ASCII letters and numbers, '.', '-' and '_'. |
| 865 | // A key cannot start with a number. |
| 866 | // See https://ecma-tc54.github.io/ECMA-427/#sec-purl-specification-rules-qualifiers. |
| 867 | func validQualifierKeyscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validQualifierKey().(key string) bool { |
| 868 | if len(key) == 0 { |
| 869 | return false |
| 870 | } |
| 871 | // First character: must be a-z, A-Z, '.', '-', or '_' |
| 872 | c := key[0] |
| 873 | if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '.' || c == '-' || c == '_') { |
| 874 | return false |
| 875 | } |
| 876 | // Remaining characters: a-z, A-Z, 0-9, '.', '-', or '_' |
| 877 | for i := 1; i < len(key); i++ { |
| 878 | c = key[i] |
| 879 | if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-' || c == '_') { |
| 880 | return false |
| 881 | } |
| 882 | } |
| 883 | return true |
| 884 | } |
| 885 | |
| 886 | // validType validates a type against our TypePattern. |
| 887 | // The type must be composed only of ASCII letters and numbers, '.', '+' and '-'. |
| 888 | // A type cannot start with a number. |
| 889 | // See https://ecma-tc54.github.io/ECMA-427/#sec-purl-specification-rules-type. |
| 890 | func validTypescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validType().(typ string) bool { |
| 891 | if len(typ) == 0 { |
| 892 | return false |
| 893 | } |
| 894 | // First character: must be a-z, A-Z, '.', '-', or '+' |
| 895 | c := typ[0] |
| 896 | if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '.' || c == '-' || c == '+') { |
| 897 | return false |
| 898 | } |
| 899 | // Remaining characters: a-z, A-Z, 0-9, '.', '-', or '+' |
| 900 | for i := 1; i < len(typ); i++ { |
| 901 | c = typ[i] |
| 902 | if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-' || c == '+') { |
| 903 | return false |
| 904 | } |
| 905 | } |
| 906 | return true |
| 907 | } |
| 908 | |
| 909 | // validChromeExtensionName checks the name against ^[a-z]{32}$. |
| 910 | func validChromeExtensionNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validChromeExtensionName().(name string) bool { |
| 911 | if len(name) != 32 { |
| 912 | return false |
| 913 | } |
| 914 | for i := 0; i < len(name); i++ { |
| 915 | if c := name[i]; c < 'a' || c > 'z' { |
| 916 | return false |
| 917 | } |
| 918 | } |
| 919 | return true |
| 920 | } |
| 921 | |
| 922 | // validChromeExtensionVersion checks the version against ^\d+(\.\d+){0,3}$. |
| 923 | func validChromeExtensionVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validChromeExtensionVersion().(version string) bool { |
| 924 | segments := 1 |
| 925 | digitsInSegment := 0 |
| 926 | for i := 0; i < len(version); i++ { |
| 927 | c := version[i] |
| 928 | if c >= '0' && c <= '9' { |
| 929 | digitsInSegment++ |
| 930 | continue |
| 931 | } |
| 932 | if c == '.' { |
| 933 | if digitsInSegment == 0 { |
| 934 | return false |
| 935 | } |
| 936 | segments++ |
| 937 | digitsInSegment = 0 |
| 938 | continue |
| 939 | } |
| 940 | return false |
| 941 | } |
| 942 | return digitsInSegment > 0 && segments <= 4 |
| 943 | } |
| 944 | |
| 945 | // validCustomRules evaluates additional rules for each package url type, as specified in the package-url specification. |
| 946 | // On success, it returns nil. On failure, a descriptive error will be returned. |
| 947 | func validCustomRulesscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validCustomRules().(p PackageURLscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#) error { |
| 948 | switch p.Typescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Type. { |
| 949 | case TypeChromeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeChromeExtension.: |
| 950 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. != "" { |
| 951 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a chrome-extension purl must not have a namespace") |
| 952 | } |
| 953 | if !validChromeExtensionNamescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validChromeExtensionName().(p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name.) { |
| 954 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a chrome-extension name must be 32 lowercase ASCII letters") |
| 955 | } |
| 956 | if p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version. != "" && !validChromeExtensionVersionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/validChromeExtensionVersion().(p.Versionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Version.) { |
| 957 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a chrome-extension version must be 1 to 4 dot-separated integers") |
| 958 | } |
| 959 | case TypeCpanscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeCpan.: |
| 960 | // It MUST be written uppercase. |
| 961 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.18 strings/ToUpper().(p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace.) != p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. { |
| 962 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a cpan purl namespace must use uppercase characters") |
| 963 | } |
| 964 | |
| 965 | // A distribution name MUST NOT contain the string '::'. |
| 966 | distName := p.Namescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Name. |
| 967 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Containsscip-go gomod github.com/golang/go/src go1.18 strings/Contains().(distName, "::") { |
| 968 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a cpan distribution name must not contain '::'") |
| 969 | } |
| 970 | case TypeJuliascip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeJulia.: |
| 971 | // The spec prohibits a namespace. |
| 972 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. != "" { |
| 973 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a julia purl must not have a namespace") |
| 974 | } |
| 975 | // The spec requires the presence of a uuid qualifier. |
| 976 | if _, ok := p.Qualifiersscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Qualifiers..Mapscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/Qualifiers#Map().()["uuid"]; !ok { |
| 977 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a julia purl must have a uuid qualifier") |
| 978 | } |
| 979 | case TypeOTPscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeOTP.: |
| 980 | // The spec prohibits a namespace. |
| 981 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. != "" { |
| 982 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("an otp purl must not have a namespace") |
| 983 | } |
| 984 | case TypeSwiftscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeSwift.: |
| 985 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. == "" { |
| 986 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("namespace is required") |
| 987 | } |
| 988 | case TypeVcpkgscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVcpkg.: |
| 989 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. != "" { |
| 990 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("a vcpkg purl must not have a namespace") |
| 991 | } |
| 992 | case TypeVSCodeExtensionscip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/TypeVSCodeExtension.: |
| 993 | if p.Namespacescip-go gomod github.com/package-url/packageurl-go . `github.com/package-url/packageurl-go`/PackageURL#Namespace. == "" { |
| 994 | return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("namespace is required") |
| 995 | } |
| 996 | } |
| 997 | return nil |
| 998 | } |