From 35d039e3ca72cf44b2b2ebcb94bf85d51003bcf4 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 May 2019 11:07:37 -0400 Subject: [PATCH 1/4] Change \r\n from matching lines to \n --- lib/bibliothecary/parsers/rubygems.rb | 3 ++- lib/bibliothecary/version.rb | 2 +- spec/parsers/rubygems_spec.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/bibliothecary/parsers/rubygems.rb b/lib/bibliothecary/parsers/rubygems.rb index bbacc641..d3478d5a 100644 --- a/lib/bibliothecary/parsers/rubygems.rb +++ b/lib/bibliothecary/parsers/rubygems.rb @@ -29,7 +29,8 @@ def self.mapping end def self.parse_gemfile_lock(manifest) - manifest.split("\n").map do |line| + manifest.each_line.map do |line| + line.chomp! match = line.match(NAME_VERSION_4) next unless match name = match[1] diff --git a/lib/bibliothecary/version.rb b/lib/bibliothecary/version.rb index ff780ce4..c605828a 100644 --- a/lib/bibliothecary/version.rb +++ b/lib/bibliothecary/version.rb @@ -1,3 +1,3 @@ module Bibliothecary - VERSION = "6.7.0" + VERSION = "6.7.1" end diff --git a/spec/parsers/rubygems_spec.rb b/spec/parsers/rubygems_spec.rb index 10c03721..0c34ef9e 100644 --- a/spec/parsers/rubygems_spec.rb +++ b/spec/parsers/rubygems_spec.rb @@ -75,6 +75,21 @@ }) end + it 'parses dependencies from Gemfile.lock with windows line endings' do + expect( + described_class.analyse_contents( + "Gemfile.lock", + "GEM\r\n remote: https://rubygems.org/\r\n specs:\r\n rails (5.2.3)\r\n")).to eq({ + :platform=>"rubygems", + :path=>"Gemfile.lock", + :dependencies=>[ + {:name=>"rails", :requirement=>"5.2.3", :type=>"runtime"}, + ], + kind: 'lockfile', + success: true + }) + end + it 'matches valid manifest filepaths' do expect(described_class.match?('devise.gemspec')).to be_truthy expect(described_class.match?('Gemfile')).to be_truthy From a4a9ac143e75d28bb9564e83f1a262627f646f4e Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 May 2019 13:09:33 -0400 Subject: [PATCH 2/4] Add better test, and fixture --- spec/fixtures/GemfileLineEndings.lock | 4 ++++ spec/parsers/rubygems_spec.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/GemfileLineEndings.lock diff --git a/spec/fixtures/GemfileLineEndings.lock b/spec/fixtures/GemfileLineEndings.lock new file mode 100644 index 00000000..2f81321e --- /dev/null +++ b/spec/fixtures/GemfileLineEndings.lock @@ -0,0 +1,4 @@ +GEM + remote: https://rubygems.org/ + specs: + rails (5.2.3) diff --git a/spec/parsers/rubygems_spec.rb b/spec/parsers/rubygems_spec.rb index 0c34ef9e..c26de506 100644 --- a/spec/parsers/rubygems_spec.rb +++ b/spec/parsers/rubygems_spec.rb @@ -76,10 +76,15 @@ end it 'parses dependencies from Gemfile.lock with windows line endings' do + fixture = load_fixture("GemfileLineEndings.lock") + # If this fails, the line endings changed, on this file. + # to fix it, run `vim spec/fixtures/GemfileLineEndings.lock +"set ff=dos" +wq` + expect(fixture).to include("\r\n") + expect( described_class.analyse_contents( "Gemfile.lock", - "GEM\r\n remote: https://rubygems.org/\r\n specs:\r\n rails (5.2.3)\r\n")).to eq({ + fixture)).to eq({ :platform=>"rubygems", :path=>"Gemfile.lock", :dependencies=>[ From 15b187f9b05b94842919dc896175e410374e12d4 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 May 2019 13:10:27 -0400 Subject: [PATCH 3/4] cleanup code now that using fixture --- spec/parsers/rubygems_spec.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/parsers/rubygems_spec.rb b/spec/parsers/rubygems_spec.rb index c26de506..7f905cdc 100644 --- a/spec/parsers/rubygems_spec.rb +++ b/spec/parsers/rubygems_spec.rb @@ -82,17 +82,15 @@ expect(fixture).to include("\r\n") expect( - described_class.analyse_contents( - "Gemfile.lock", - fixture)).to eq({ - :platform=>"rubygems", - :path=>"Gemfile.lock", - :dependencies=>[ - {:name=>"rails", :requirement=>"5.2.3", :type=>"runtime"}, - ], - kind: 'lockfile', - success: true - }) + described_class.analyse_contents("Gemfile.lock", fixture)).to eq({ + :platform=>"rubygems", + :path=>"Gemfile.lock", + :dependencies=>[ + {:name=>"rails", :requirement=>"5.2.3", :type=>"runtime"}, + ], + kind: 'lockfile', + success: true + }) end it 'matches valid manifest filepaths' do From d574ee22ced988cf878ff8b5edd3665478b3196e Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 May 2019 13:24:37 -0400 Subject: [PATCH 4/4] lines.chomp true --- lib/bibliothecary/parsers/rubygems.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bibliothecary/parsers/rubygems.rb b/lib/bibliothecary/parsers/rubygems.rb index d3478d5a..32b04c2f 100644 --- a/lib/bibliothecary/parsers/rubygems.rb +++ b/lib/bibliothecary/parsers/rubygems.rb @@ -29,8 +29,7 @@ def self.mapping end def self.parse_gemfile_lock(manifest) - manifest.each_line.map do |line| - line.chomp! + manifest.lines(chomp: true).map do |line| match = line.match(NAME_VERSION_4) next unless match name = match[1]