Skip to content

Commit 29c338d

Browse files
author
Matt Ellis
committed
Add NONE and NOASSERTION as valid spdx, also make empty string invalid
1 parent c0b40cf commit 29c338d

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
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?("(") || data == "NONE" || data == "NOASSERTION"
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
grammar SpdxGrammar
22

3-
rule top_level_spdx
4-
"NONE" / "NOASSERTION" / compound_expression
3+
rule spdx_expression
4+
compound_expression / none / no_assertion
55
end
66

77
rule compound_expression
@@ -36,6 +36,14 @@ grammar SpdxGrammar
3636
"AND" / "OR" / "WITH"
3737
end
3838

39+
rule none
40+
"NONE" <None>
41+
end
42+
43+
rule no_assertion
44+
"NOASSERTION" <NoAssertion>
45+
end
46+
3947
rule space
4048
[\s]+
4149
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)