From aaf292fdec3f6f01b45d468ffa80df721c867acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 15 Sep 2022 23:04:09 +0200 Subject: [PATCH] Fix multiple Python requirements separated by whitespace Standard Python does not support this, but Poetry does, so when they appear on Poetry dependency files, they make dependabot crash. --- python/lib/dependabot/python/requirement.rb | 3 +++ python/spec/dependabot/python/requirement_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/python/lib/dependabot/python/requirement.rb b/python/lib/dependabot/python/requirement.rb index 62414a2911..cc1326ef04 100644 --- a/python/lib/dependabot/python/requirement.rb +++ b/python/lib/dependabot/python/requirement.rb @@ -60,6 +60,9 @@ def initialize(*requirements) requirements = requirements.flatten.flat_map do |req_string| next if req_string.nil? + # Standard python doesn't support whitespace in requirements, but Poetry does. + req_string = req_string.gsub(/(\d +)([<=>])/, '\1,\2') + req_string.split(",").map(&:strip).map do |r| convert_python_constraint_to_ruby_constraint(r) end diff --git a/python/spec/dependabot/python/requirement_spec.rb b/python/spec/dependabot/python/requirement_spec.rb index 001a273103..a50bec19c5 100644 --- a/python/spec/dependabot/python/requirement_spec.rb +++ b/python/spec/dependabot/python/requirement_spec.rb @@ -114,6 +114,11 @@ let(:requirement_string) { ">=2.0,<2.1" } it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1")) } end + + context "separated by whitespace (supported by Poetry)" do + let(:requirement_string) { ">=2.0 <2.1" } + it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1")) } + end end context "with multiple operators after the first" do @@ -125,6 +130,11 @@ let(:requirement_string) { ">=2.0,<2.1,<2.2" } it { is_expected.to eq(Gem::Requirement.new(">=2.0", "<2.1", "<2.2")) } end + + context "separated by whitespace (supported by Poetry)" 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