Skip to content

Commit

Permalink
util: fix parsing of copyrights without year
Browse files Browse the repository at this point in the history
Fixes a crash when reuse tries to parse an older Copyright line
which has no year token. This resulted in a None dereference
when a string was expected.

Signed-off-by: Anthony Loiseau <anthony.loiseau@allcircuits.com>
  • Loading branch information
anthony-loiseau-act committed Nov 17, 2023
1 parent 4de4450 commit 7bf6cb3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
@@ -295,9 +295,9 @@ def _parse_copyright_year(year: str) -> list:
"""Parse copyright years and return list."""
if not year:
ret = []
if re.match(r"\d{4}$", year):
elif re.match(r"\d{4}$", year):
ret = [int(year)]
if re.match(r"\d{4} ?- ?\d{4}$", year):
elif re.match(r"\d{4} ?- ?\d{4}$", year):
ret = [int(year[:4]), int(year[-4:])]
return ret

@@ -393,7 +393,9 @@ def merge_copyright_lines(copyright_lines: Set[str]) -> Set[str]:
years += copy["year"]

year: Optional[str] = None
if min(years) == max(years):
if not years:
year = None
elif min(years) == max(years):
year = min(years)
else:
year = f"{min(years)} - {max(years)}"

0 comments on commit 7bf6cb3

Please sign in to comment.