Skip to content

Commit

Permalink
Restore support for YYYY copyright lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Aug 30, 2023
1 parent 2730cc3 commit 2a631f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
5 changes: 3 additions & 2 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,18 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
Legal formats are:
* ``YYYY``
* ``YYYY,``
* ``YYYY ``
* ``YYYY-YYYY,``
* ``YYYY-YYYY ``
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] != '-':
Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-copyright-multiline/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
copyright = (
'2006',
'2006-2009, Alice',
'2010-2013, Bob',
'2014-2017, Charlie',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand Down

0 comments on commit 2a631f9

Please sign in to comment.