File tree Expand file tree Collapse file tree 5 files changed +28
-3
lines changed
Expand file tree Collapse file tree 5 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module Spdx
4- VERSION = "2.0.2 "
4+ VERSION = "2.0.3 "
55end
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ class LogicalAnd < Treetop::Runtime::SyntaxNode
1616 class With < Treetop ::Runtime ::SyntaxNode
1717 end
1818
19+ class None < Treetop ::Runtime ::SyntaxNode
20+ end
21+
22+ class NoAssertion < Treetop ::Runtime ::SyntaxNode
23+ end
24+
1925 class License < Treetop ::Runtime ::SyntaxNode
2026 def licenses
2127 text_value
Original file line number Diff line number Diff line change 88class SpdxParser
99 Treetop . load ( File . expand_path ( File . join ( File . dirname ( __FILE__ ) , "spdx_parser.treetop" ) ) )
1010
11+ SKIP_PARENS = [ "NONE" , "NOASSERTION" , "" ]
1112 @parser = SpdxGrammarParser . new
1213
1314 def self . parse ( data )
@@ -21,8 +22,7 @@ def self.parse_licenses(data)
2122
2223 private_class_method def self . parse_tree ( data )
2324 # Couldn't figure out treetop to make parens optional
24- data = "(#{ data } )" unless data . start_with? ( "(" )
25-
25+ data = "(#{ data } )" unless data . start_with? ( "(" ) || SKIP_PARENS . include? ( data )
2626 tree = @parser . parse ( data )
2727
2828 raise SpdxGrammar ::SpdxParseError , "Parse error at offset: #{ @parser . index } " if tree . nil?
Original file line number Diff line number Diff line change 11grammar SpdxGrammar
22
3+ rule spdx_expression
4+ compound_expression / none / no_assertion
5+ end
6+
37 rule compound_expression
48 '(' body ')' <CompoundExpression>
59 end
@@ -32,6 +36,14 @@ grammar SpdxGrammar
3236 "AND" / "OR" / "WITH"
3337 end
3438
39+ rule none
40+ "NONE" <None>
41+ end
42+
43+ rule no_assertion
44+ "NOASSERTION" <NoAssertion>
45+ end
46+
3547 rule space
3648 [\s]+
3749 end
Original file line number Diff line number Diff line change 188188 expect ( Spdx . valid_spdx? ( "MIT OR MIT AND OR" ) ) . to be false
189189 expect ( Spdx . valid_spdx? ( "MIT OR FAKEYLICENSE" ) ) . to be false
190190 expect ( Spdx . valid_spdx? ( nil ) ) . to be false
191+ expect ( Spdx . valid_spdx? ( "" ) ) . to be false
191192 end
192193 it "returns true for valid spdx" do
193194 expect ( Spdx . valid_spdx? ( "(MIT OR MPL-2.0)" ) ) . to be true
194195 expect ( Spdx . valid_spdx? ( "MIT" ) ) . to be true
195196 expect ( Spdx . valid_spdx? ( "((MIT OR AGPL-1.0) AND (MIT OR MPL-2.0))" ) ) . to be true
196197 end
198+ it "returns true for NONE and NOASSERTION" do
199+ expect ( Spdx . valid_spdx? ( "NONE" ) ) . to be true
200+ expect ( Spdx . valid_spdx? ( "(NONE)" ) ) . to be false
201+ expect ( Spdx . valid_spdx? ( "NOASSERTION" ) ) . to be true
202+ expect ( Spdx . valid_spdx? ( "MIT OR NONE" ) ) . to be false
203+ end
197204 end
198205 end
199206 context "alias lookup" do
You can’t perform that action at this time.
0 commit comments