Skip to content

Commit f12b5f8

Browse files
committed
[issue-465] correct regex to match spaces or tabs and add a test for this
Signed-off-by: Meret Behrens <[email protected]>
1 parent 9858d21 commit f12b5f8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spdx/parsers/lexers/tagvalue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def t_newline(self, t):
235235
t.lexer.lineno += len(t.value)
236236

237237
def t_whitespace(self, t):
238-
r"\s"
238+
r"[ \t]+"
239239
pass
240240

241241
def build(self, **kwargs):

tests/test_tag_value_parser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
'SPDXREF: SPDXRef-DOCUMENT'
116116
])
117117

118+
document_str_with_empty_line = "\n".join(
119+
['SPDXVersion: SPDX-2.1', ' ', 'DataLicense: CC0-1.0'])
120+
118121

119122
class TestLexer(TestCase):
120123
maxDiff = None
@@ -291,6 +294,14 @@ def test_annotation(self):
291294
self.token_assert_helper(self.l.token(), 'ANNOTATION_SPDX_ID', 'SPDXREF', 5)
292295
self.token_assert_helper(self.l.token(), 'LINE', 'SPDXRef-DOCUMENT', 5)
293296

297+
def test_correct_line_number_with_empty_line_between(self):
298+
data = document_str_with_empty_line
299+
self.l.input(data)
300+
self.token_assert_helper(self.l.token(), 'DOC_VERSION', 'SPDXVersion', 1)
301+
self.token_assert_helper(self.l.token(), 'LINE', 'SPDX-2.1', 1)
302+
self.token_assert_helper(self.l.token(), 'DOC_LICENSE', 'DataLicense', 3)
303+
self.token_assert_helper(self.l.token(), 'LINE', 'CC0-1.0', 3)
304+
294305
def token_assert_helper(self, token, ttype, value, line):
295306
assert token.type == ttype
296307
assert token.value == value

0 commit comments

Comments
 (0)