diff --git a/sphinx/config.py b/sphinx/config.py index 5675cfba3..22b98a834 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -610,7 +610,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str: if copyright_line[4] != '-': return copyright_line - if copyright_line[5:9].isdigit() and copyright_line[9] in ' ,': + if copyright_line[5:9].isdigit() and copyright_line[9:10] in {'', ' ', ','}: return copyright_line[:5] + replace_year + copyright_line[9:] return copyright_line diff --git a/tests/test_config/test_config.py b/tests/test_config/test_config.py index 317a50bf3..ee305274e 100644 --- a/tests/test_config/test_config.py +++ b/tests/test_config/test_config.py @@ -8,7 +8,13 @@ import pytest import sphinx from sphinx.builders.gettext import _gettext_compact_validator -from sphinx.config import ENUM, Config, _Opt, check_confval_types +from sphinx.config import ( + ENUM, + Config, + _Opt, + check_confval_types, + correct_copyright_year, +) from sphinx.deprecation import RemovedInSphinx90Warning from sphinx.errors import ConfigError, ExtensionError, VersionRequirementError @@ -556,6 +562,24 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch): ) in content +@pytest.mark.parametrize(('conf_copyright', 'expected_copyright'), [ + ('1970', '{current_year}'), + # https://github.com/sphinx-doc/sphinx/issues/11913 + ('1970-1990', '1970-{current_year}'), + ('1970-1990 Alice', '1970-{current_year} Alice'), +]) +def test_correct_copyright_year(conf_copyright, expected_copyright, source_date_year): + config = Config({}, {'copyright': conf_copyright}) + correct_copyright_year(_app=None, config=config) + actual_copyright = config['copyright'] + + if source_date_year is None: + expected_copyright = conf_copyright + else: + expected_copyright = expected_copyright.format(current_year=source_date_year) + assert actual_copyright == expected_copyright + + def test_gettext_compact_command_line_true(): config = Config({}, {'gettext_compact': '1'}) config.add('gettext_compact', True, '', {bool, str})