diff --git a/lib/ronin/support/text/patterns/software.rb b/lib/ronin/support/text/patterns/software.rb index d7fcd9d0..ff4b3ca2 100644 --- a/lib/ronin/support/text/patterns/software.rb +++ b/lib/ronin/support/text/patterns/software.rb @@ -36,6 +36,11 @@ module Patterns # # @since 1.2.0 VERSION_CONSTRAINT = /(?:>=|>|<=|<|=)\s*#{VERSION_NUMBER}/ + + # Regular expression for finding version ranges in text. + # + # @since 1.2.0 + VERSION_RANGE = /#{VERSION_CONSTRAINT}(?:(?:,\s*|\s+)#{VERSION_CONSTRAINT})?/ end end end diff --git a/spec/text/patterns/software_spec.rb b/spec/text/patterns/software_spec.rb index 7a5b87b4..77b49f2f 100644 --- a/spec/text/patterns/software_spec.rb +++ b/spec/text/patterns/software_spec.rb @@ -975,4 +975,32 @@ expect('=1.2.3').to fully_match(subject) end end + + describe "VERSION_RANGE" do + subject { described_class::VERSION_RANGE } + + it "must match '(>=|>|<=|<|=) X.Y.Z'" do + expect('>= 1.2.3').to fully_match(subject) + end + + it "must match '(>=|>|<=|<|=)X.Y.Z'" do + expect('>=1.2.3').to fully_match(subject) + end + + it "must match '(>=|>|<=|<|=) X.Y.Z, (>=|>|<=|<|=) A.B.C'" do + expect('>= 1.2.3, < 2.0.0').to fully_match(subject) + end + + it "must match '(>=|>|<=|<|=)X.Y.Z,(>=|>|<=|<|=)A.B.C'" do + expect('>=1.2.3,<2.0.0').to fully_match(subject) + end + + it "must match '(>=|>|<=|<|=) X.Y.Z (>=|>|<=|<|=) A.B.C'" do + expect('>= 1.2.3 < 2.0.0').to fully_match(subject) + end + + it "must match '(>=|>|<=|<|=)X.Y.Z (>=|>|<=|<|=)A.B.C'" do + expect('>=1.2.3 <2.0.0').to fully_match(subject) + end + end end