diff --git a/python/lib/dependabot/python/requirement.rb b/python/lib/dependabot/python/requirement.rb index 62fc86da1cf..62414a29114 100644 --- a/python/lib/dependabot/python/requirement.rb +++ b/python/lib/dependabot/python/requirement.rb @@ -87,7 +87,7 @@ def convert_python_constraint_to_ruby_constraint(req_string) return nil if req_string == "*" req_string = req_string.gsub("~=", "~>") - req_string = req_string.gsub(/(?<=\d)[<=>].*/, "") + req_string = req_string.gsub(/(?<=\d)[<=>].*\Z/, "") if req_string.match?(/~[^>]/) then convert_tilde_req(req_string) elsif req_string.start_with?("^") then convert_caret_req(req_string) diff --git a/python/spec/dependabot/python/requirement_spec.rb b/python/spec/dependabot/python/requirement_spec.rb index 789945206e2..001a2731039 100644 --- a/python/spec/dependabot/python/requirement_spec.rb +++ b/python/spec/dependabot/python/requirement_spec.rb @@ -116,6 +116,17 @@ end end + context "with multiple operators after the first" do + let(:requirement_string) { ">=2.0<2.1<2.2" } + # Python ignores operators after the first! + it { is_expected.to eq(Gem::Requirement.new(">=2.0")) } + + context "separated with a comma" do + let(:requirement_string) { ">=2.0,<2.1,<2.2" } + it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1", "<2.2")) } + end + end + context "with an array" do let(:requirement_string) { ["== 1.3.*", ">= 1.3.1"] } its(:to_s) do