Restore support for YYYY copyright lines

This commit is contained in:
Adam Turner 2023-08-30 22:51:23 +01:00
parent 2730cc3353
commit 2a631f97ef
4 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,8 @@ Bugs fixed
the :dudir:`include` directive.
* 11620: Add a new :event:`include-read` for observing and transforming
the content of included files via the :dudir:`include` directive.
* #11627: Restore support for copyright lines of the form ``YYYY``
when ``SOURCE_DATE_EPOCH`` is set.
Testing
-------

View File

@ -446,6 +446,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
Legal formats are:
* ``YYYY``
* ``YYYY,``
* ``YYYY ``
* ``YYYY-YYYY,``
@ -453,10 +454,10 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
The final year in the string is replaced with ``replace_year``.
"""
if not copyright_line[:4].isdigit():
if len(copyright_line) < 4 or not copyright_line[:4].isdigit():
return copyright_line
if copyright_line[4] in ' ,':
if copyright_line[4:5] in {'', ' ', ','}:
return replace_year + copyright_line[4:]
if copyright_line[4] != '-':

View File

@ -1,4 +1,5 @@
copyright = (
'2006',
'2006-2009, Alice',
'2010-2013, Bob',
'2014-2017, Charlie',

View File

@ -471,6 +471,7 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
if source_date_year is None:
# check the copyright footer line by line (empty lines ignored)
assert ' &#169; Copyright 2006.<br/>\n' in content
assert ' &#169; Copyright 2006-2009, Alice.<br/>\n' in content
assert ' &#169; Copyright 2010-2013, Bob.<br/>\n' in content
assert ' &#169; Copyright 2014-2017, Charlie.<br/>\n' in content
@ -479,6 +480,8 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
# check the raw copyright footer block (empty lines included)
assert (
' &#169; Copyright 2006.<br/>\n'
' \n'
' &#169; Copyright 2006-2009, Alice.<br/>\n'
' \n'
' &#169; Copyright 2010-2013, Bob.<br/>\n'
@ -491,6 +494,7 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
) in content
else:
# check the copyright footer line by line (empty lines ignored)
assert f' &#169; Copyright {source_date_year}.<br/>\n' in content
assert f' &#169; Copyright 2006-{source_date_year}, Alice.<br/>\n' in content
assert f' &#169; Copyright 2010-{source_date_year}, Bob.<br/>\n' in content
assert f' &#169; Copyright 2014-{source_date_year}, Charlie.<br/>\n' in content
@ -499,6 +503,8 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
# check the raw copyright footer block (empty lines included)
assert (
f' &#169; Copyright {source_date_year}.<br/>\n'
f' \n'
f' &#169; Copyright 2006-{source_date_year}, Alice.<br/>\n'
f' \n'
f' &#169; Copyright 2010-{source_date_year}, Bob.<br/>\n'