Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spdx_tools/spdx/parser/tagvalue/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def t_text_error(self, t):

@TOKEN(
r":\s*(ADLER32|BLAKE2b-256|BLAKE2b-384|BLAKE2b-512|BLAKE3|MD2|MD4|MD5|MD6|SHA1|SHA224|SHA256|SHA384|SHA512|"
r"SHA3-256|SHA3-384|SHA3-512):\s*([a-f0-9]*)"
r"SHA3-256|SHA3-384|SHA3-512):\s*([a-f0-9]+)"
)
def t_CHECKSUM(self, t):
t.value = t.value[1:].strip()
Expand Down
14 changes: 14 additions & 0 deletions tests/spdx/parser/tagvalue/test_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ def test_parse_invalid_file():
"Error while parsing File: ['Invalid FileType: SOUCE. Line 3', 'Error while "
"parsing FileChecksum: Token did not match specified grammar rule. Line: 5']"
]


def test_parse_file_uppercase_checksum_raises():
# An uppercase checksum value used to silently produce Checksum(SHA1, "")
# instead of raising; the lexer must reject it as a grammar error.
file_str = "\n".join(
[
"FileName: f",
"SPDXID: SPDXRef-File",
"FileChecksum: SHA1: D6A770BA38583ED4BB4525BD96E50461655D2758",
]
)
with pytest.raises(SPDXParsingError):
Parser().parse("\n".join([DOCUMENT_STR, file_str]))