diff --git a/CHANGES b/CHANGES index 99f1a420060..fb7bbc21cc1 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------- diff --git a/sphinx/config.py b/sphinx/config.py index 598ec644331..405ca5e8deb 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -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] != '-': diff --git a/tests/roots/test-copyright-multiline/conf.py b/tests/roots/test-copyright-multiline/conf.py index 24bd0c5291f..a2b7b680100 100644 --- a/tests/roots/test-copyright-multiline/conf.py +++ b/tests/roots/test-copyright-multiline/conf.py @@ -1,4 +1,5 @@ copyright = ( + '2006', '2006-2009, Alice', '2010-2013, Bob', '2014-2017, Charlie', diff --git a/tests/test_config.py b/tests/test_config.py index 41b737e01b0..0be0a588cfb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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 ' © Copyright 2006.
\n' in content assert ' © Copyright 2006-2009, Alice.
\n' in content assert ' © Copyright 2010-2013, Bob.
\n' in content assert ' © Copyright 2014-2017, Charlie.
\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 ( + ' © Copyright 2006.
\n' + ' \n' ' © Copyright 2006-2009, Alice.
\n' ' \n' ' © Copyright 2010-2013, Bob.
\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' © Copyright {source_date_year}.
\n' in content assert f' © Copyright 2006-{source_date_year}, Alice.
\n' in content assert f' © Copyright 2010-{source_date_year}, Bob.
\n' in content assert f' © Copyright 2014-{source_date_year}, Charlie.
\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' © Copyright {source_date_year}.
\n' + f' \n' f' © Copyright 2006-{source_date_year}, Alice.
\n' f' \n' f' © Copyright 2010-{source_date_year}, Bob.
\n'