Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: fix parsing of copyrights without year #861

Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ CLI command and its behaviour. There are no guarantees of stability for the
- Reduced python-debian minimum version to 0.1.34. (#808)
- Fix issue in `annotate` where `--single-line` and `--multi-line` would not
correctly raise an error with an incompatible comment style. (#853)
- Fix parsing existing copyright lines when they do not have a year (#861)

### Security

Expand Down
8 changes: 5 additions & 3 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)}"
Expand Down