Skip to content

Commit 9e80cc7

Browse files
author
Matt Ellis
authored
Merge pull request #56 from librariesio/mellisio/spdx/add-none-and-noassertion
2 parents 978fe6a + 29c338d commit 9e80cc7

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

lib/spdx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Spdx
4-
VERSION = "2.0.2"
4+
VERSION = "2.0.3"
55
end

lib/spdx_grammar.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

lib/spdx_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class 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?

lib/spdx_parser.treetop

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
grammar 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

spec/spdx_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@
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

0 commit comments

Comments
 (0)