Commit b058166

mo khan <mo.khan@gmail.com>
2020-05-17 20:20:04
Skip empty lock files
1 parent 770e916
Changed files (4)
lib
spandx
spec
fixtures
unit
lib/spandx/core/parser.rb
@@ -21,6 +21,8 @@ module Spandx
         include Registerable
 
         def for(path)
+          return UNKNOWN if File.size(path).zero?
+
           find { |x| x.matches?(File.basename(path)) } || UNKNOWN
         end
       end
spec/fixtures/empty/composer.lock
spec/unit/core/parser_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Core::Parser do
+  subject { described_class }
+
+  describe ".for" do
+    describe "when the `composer.lock` file is empty" do
+      let(:empty_file) { fixture_file('empty/composer.lock') }
+      let(:result) { subject.for(empty_file) }
+
+      specify { expect(result).to be(Spandx::Core::Parser::UNKNOWN) }
+    end
+
+    describe "when the `composer.lock` file is discovered" do
+      let(:lock_file) { fixture_file('composer/composer.lock') }
+      let(:result) { subject.for(lock_file) }
+
+      specify { expect(result).to be_instance_of(Spandx::Php::Parsers::Composer) }
+    end
+  end
+end
CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ## [0.13.2] - 2020-05-17
 ### Fixed
 - Detect licenses when provided as an array.
+- Skip empty lockfiles.
 
 ## [0.13.1] - 2020-05-16
 ### Fixed