semver_dialects 1.6.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf47952cc234d33748963e58c0705c505099123cc31c3add7ae0327ae71602a
|
4
|
+
data.tar.gz: f98d8ae7b8132c48c3e532829dcd681ab05fa5c75114ff640704ee9c3b08ee35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f679d527db82d52b690e0e055c3313f45f0b27ecd79e72f98a0ed0f0b79a7d3345cc322eb4d02ca2522bcaa6ddf1de319d2c09cd876e85cdc739249a77664410
|
7
|
+
data.tar.gz: 6a82935c5c66b18d7a61fa99df1ff176976b5d48b72297289b14c4123e628e15b0462cd8fa2a5cb0f21448c34e7fb5818879d1c157d554470be5de0781854f15
|
@@ -5,7 +5,21 @@ require_relative '../../utils.rb'
|
|
5
5
|
class SemanticVersion
|
6
6
|
attr_reader :version_string, :prefix_delimiter, :prefix_segments, :suffix_segments, :segments
|
7
7
|
|
8
|
+
# String to build a regexp that matches a version.
|
9
|
+
#
|
10
|
+
# A version might start with a leading "v", then it must have a digit,
|
11
|
+
# then it might have any sequence made of alphanumerical characters,
|
12
|
+
# underscores, dots, dashes, and wildcards.
|
13
|
+
VERSION_PATTERN = "v?[0-9][a-zA-Z0-9_.*+-]*"
|
14
|
+
|
15
|
+
# Regexp for a string that only contains a single version string.
|
16
|
+
VERSION_ONLY_REGEXP = Regexp.new("\\A#{VERSION_PATTERN}\\z").freeze
|
17
|
+
|
8
18
|
def initialize(version_string, segments = nil)
|
19
|
+
unless VERSION_ONLY_REGEXP.match version_string
|
20
|
+
raise SemverDialects::InvalidVersionError, version_string
|
21
|
+
end
|
22
|
+
|
9
23
|
@version_string = version_string
|
10
24
|
@prefix_segments = []
|
11
25
|
@suffix_segments = []
|
@@ -2,6 +2,9 @@ require_relative "version_cut"
|
|
2
2
|
require_relative "version_interval"
|
3
3
|
|
4
4
|
module VersionParser
|
5
|
+
# A constraint is made of an operator followed by a version string.
|
6
|
+
CONSTRAINT_REGEXP = Regexp.new("(?<op>[><=]+) *(?<version>#{SemanticVersion::VERSION_PATTERN})").freeze
|
7
|
+
|
5
8
|
def self.parse(versionstring)
|
6
9
|
if (versionstring == "=*")
|
7
10
|
# special case = All Versions
|
@@ -10,9 +13,9 @@ module VersionParser
|
|
10
13
|
|
11
14
|
version_items = versionstring.split(" ")
|
12
15
|
interval = VersionInterval.new(IntervalType::LEFT_OPEN | IntervalType::RIGHT_OPEN, BelowAll.new(), AboveAll.new())
|
13
|
-
version_items.each do
|
14
|
-
|
15
|
-
|
16
|
+
version_items.each do |version_item|
|
17
|
+
matches = version_item.match CONSTRAINT_REGEXP
|
18
|
+
raise SemverDialects::InvalidConstraintError, versionstring if matches.nil?
|
16
19
|
version_string = matches[:version]
|
17
20
|
case matches[:op]
|
18
21
|
when ">="
|
data/lib/semver_dialects.rb
CHANGED
@@ -14,6 +14,36 @@ module SemverDialects
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
class UnsupportedPackageTypeError < Error
|
18
|
+
def initialize(pkgType)
|
19
|
+
@pkgType = pkgType
|
20
|
+
end
|
21
|
+
|
22
|
+
def message
|
23
|
+
"unsupported package type '#{@pkgType}'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class InvalidVersionError < Error
|
28
|
+
def initialize(raw_version)
|
29
|
+
@raw_version = raw_version
|
30
|
+
end
|
31
|
+
|
32
|
+
def message
|
33
|
+
"invalid version '#{@raw_version}'"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidConstraintError < Error
|
38
|
+
def initialize(raw_constraint)
|
39
|
+
@raw_constraint = raw_constraint
|
40
|
+
end
|
41
|
+
|
42
|
+
def message
|
43
|
+
"invalid constraint '#{@raw_constraint}'"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
17
47
|
# A utiltity module that helps with version matching
|
18
48
|
module VersionChecker
|
19
49
|
def self.version_translate(typ, version_string)
|
@@ -35,26 +65,32 @@ module SemverDialects
|
|
35
65
|
when 'packagist'
|
36
66
|
VersionTranslator.translate_packagist(version_string)
|
37
67
|
else
|
38
|
-
raise
|
68
|
+
raise UnsupportedPackageTypeError, typ
|
39
69
|
end
|
40
70
|
end
|
41
71
|
|
72
|
+
# Determines if a version of a given package type satisfies a constraint.
|
73
|
+
#
|
74
|
+
# On normal execution, this method might raise the following exceptions:
|
75
|
+
#
|
76
|
+
# - UnsupportedPackageTypeError if the package type is not supported
|
77
|
+
# - InvalidVersionError if the version is invalid
|
78
|
+
# - InvalidConstraintError if the constraint is invalid or contains invalid versions
|
79
|
+
#
|
42
80
|
def self.version_sat?(typ, raw_ver, raw_constraint)
|
43
81
|
# os package versions are handled very differently from application package versions
|
44
82
|
return os_pkg_version_sat?(typ, raw_ver, raw_constraint) if os_purl_type?(typ)
|
45
83
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
version = VersionParser.parse('=' + raw_ver)
|
50
|
-
raise SemverDialects::Error, 'malformed constraint' if version.nil? || version.empty?
|
84
|
+
# build an interval that only contains the version
|
85
|
+
version = VersionCut.new(raw_ver)
|
86
|
+
version_as_interval = VersionInterval.new(IntervalType::LEFT_CLOSED | IntervalType::RIGHT_CLOSED, version, version)
|
51
87
|
|
52
88
|
constraint = VersionRange.new
|
53
|
-
|
89
|
+
version_translate(typ, raw_constraint).each do |version_interval_str|
|
54
90
|
constraint << VersionParser.parse(version_interval_str)
|
55
91
|
end
|
56
92
|
|
57
|
-
constraint.overlaps_with?(
|
93
|
+
constraint.overlaps_with?(version_as_interval)
|
58
94
|
end
|
59
95
|
|
60
96
|
def self.os_purl_type?(typ)
|
@@ -65,7 +101,7 @@ module SemverDialects
|
|
65
101
|
if typ == 'deb'
|
66
102
|
# we only support the less than operator, because that's the only one currently output
|
67
103
|
# by the advisory exporter for operating system packages.
|
68
|
-
raise SemverDialects::
|
104
|
+
raise SemverDialects::InvalidConstraintError, raw_constraint unless raw_constraint[0] == '<'
|
69
105
|
|
70
106
|
v1 = DebVersion.new(raw_ver)
|
71
107
|
v2 = DebVersion.new(raw_constraint[1..-1])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semver_dialects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Thome
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-03-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pastel
|
@@ -74,14 +74,14 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 2.4
|
77
|
+
version: '2.4'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: 2.4
|
84
|
+
version: '2.4'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: rake
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,8 +152,8 @@ licenses:
|
|
152
152
|
metadata:
|
153
153
|
allowed_push_host: https://rubygems.org
|
154
154
|
homepage_uri: https://rubygems.org/gems/semver_dialects
|
155
|
-
source_code_uri: https://gitlab.com/gitlab-org/
|
156
|
-
changelog_uri: https://gitlab.com/gitlab-org/
|
155
|
+
source_code_uri: https://gitlab.com/gitlab-org/ruby/gems/semver_dialects
|
156
|
+
changelog_uri: https://gitlab.com/gitlab-org/ruby/gems/semver_dialects/-/blob/master/CHANGELOG.md
|
157
157
|
post_install_message:
|
158
158
|
rdoc_options: []
|
159
159
|
require_paths:
|