Class: Homebrew::Vulns::Purl Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
A package URL per https://github.com/package-url/purl-spec.
Minimal builder for the registry types Homebrew derives from formula source URLs. Applies the spec's per-type name normalisation and RFC 3986 percent-encoding when serialised. Parsing, qualifiers and subpath are intentionally omitted.
Instance Attribute Summary collapse
- #name ⇒ String readonly private
- #namespace ⇒ String? readonly private
- #type ⇒ String readonly private
- #version ⇒ String? readonly private
Class Method Summary collapse
-
.encode(component) ⇒ String
private
Percent-encode a single purl component.
-
.normalize(type, namespace, name) ⇒ Array<([String, nil], String)>
private
Per-type normalisation from purl-spec PURL-TYPES.rst for the types we emit.
Instance Method Summary collapse
- #initialize(type:, name:, namespace: nil, version: nil) ⇒ void constructor private
Constructor Details
#initialize(type:, name:, namespace: nil, version: nil) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'vulns/purl.rb', line 22 def initialize(type:, name:, namespace: nil, version: nil) raise ArgumentError, "type is required" if type.empty? raise ArgumentError, "name is required" if name.empty? @type = T.let(type.downcase.freeze, String) namespace = nil if namespace && namespace.empty? namespace, name = self.class.normalize(@type, namespace, name) @namespace = T.let(namespace && -namespace, T.nilable(String)) @name = T.let(-name, String) version = nil if version && version.empty? @version = T.let(version && -version, T.nilable(String)) end |
Instance Attribute Details
#name ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
14 15 16 |
# File 'vulns/purl.rb', line 14 def name @name end |
#namespace ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
17 18 19 |
# File 'vulns/purl.rb', line 17 def namespace @namespace end |
#type ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
14 15 16 |
# File 'vulns/purl.rb', line 14 def type @type end |
#version ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
17 18 19 |
# File 'vulns/purl.rb', line 17 def version @version end |
Class Method Details
.encode(component) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Percent-encode a single purl component. The spec permits the RFC 3986
unreserved set plus : unencoded; + for space is forbidden so
URI.encode_www_form_component is unsuitable.
67 68 69 |
# File 'vulns/purl.rb', line 67 def self.encode(component) component.b.gsub(/[^A-Za-z0-9\-._~:]/n) { |c| format("%%%02X", c.ord) } end |
.normalize(type, namespace, name) ⇒ Array<([String, nil], String)>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Per-type normalisation from purl-spec PURL-TYPES.rst for the types we emit.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'vulns/purl.rb', line 76 def self.normalize(type, namespace, name) case type when "pypi" [namespace, name.downcase.tr("_", "-")] when "hex" [namespace&.downcase, name.downcase] when "cpan" [namespace&.upcase, name] else [namespace, name] end end |