Restrict substitution of `copyright` years (#12516)

Only substitute copyright notice years with values from
``SOURCE_DATE_EPOCH`` for entries that match the current
system clock year, and disallow substitution of future years.

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
James Addison
2024-10-04 09:48:47 +00:00
committed by GitHub
parent 5eb68b2bff
commit a84f7009ac
4 changed files with 72 additions and 45 deletions

View File

@@ -2,16 +2,21 @@ import time
import pytest
LT = time.localtime()
LT_NEW = (2009, *LT[1:], LT.tm_zone, LT.tm_gmtoff)
LOCALTIME_2009 = type(LT)(LT_NEW)
@pytest.fixture(
params=[
1293840000, # 2011-01-01 00:00:00
1293839999, # 2010-12-31 23:59:59
1199145600, # 2008-01-01 00:00:00
1199145599, # 2007-12-31 23:59:59
]
)
def source_date_year(request, monkeypatch):
source_date_epoch = request.param
with monkeypatch.context() as m:
m.setattr(time, 'localtime', lambda *a: LOCALTIME_2009)
m.setenv('SOURCE_DATE_EPOCH', str(source_date_epoch))
yield time.gmtime(source_date_epoch).tm_year
@@ -53,24 +58,24 @@ def test_html_multi_line_copyright_sde(source_date_year, app):
content = (app.outdir / 'index.html').read_text(encoding='utf-8')
# check the copyright footer line by line (empty lines ignored)
assert f' &#169; Copyright {source_date_year}.<br/>\n' in content
assert ' &#169; Copyright 2006.<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
assert f' &#169; Copyright 2018-{source_date_year}, David.<br/>\n' in content
assert f' &#169; Copyright 2022-{source_date_year}, Eve.' in content
assert ' &#169; Copyright 2010-2013, Bob.<br/>\n' in content
assert ' &#169; Copyright 2014-2017, Charlie.<br/>\n' in content
assert ' &#169; Copyright 2018-2021, David.<br/>\n' in content
assert ' &#169; Copyright 2022-2025, Eve.' in content
# check the raw copyright footer block (empty lines included)
assert (
f' &#169; Copyright {source_date_year}.<br/>\n'
f' \n'
' &#169; Copyright 2006.<br/>\n'
' \n'
f' &#169; Copyright 2006-{source_date_year}, Alice.<br/>\n'
f' \n'
f' &#169; Copyright 2010-{source_date_year}, Bob.<br/>\n'
f' \n'
f' &#169; Copyright 2014-{source_date_year}, Charlie.<br/>\n'
f' \n'
f' &#169; Copyright 2018-{source_date_year}, David.<br/>\n'
f' \n'
f' &#169; Copyright 2022-{source_date_year}, Eve.'
' \n'
' &#169; Copyright 2010-2013, Bob.<br/>\n'
' \n'
' &#169; Copyright 2014-2017, Charlie.<br/>\n'
' \n'
' &#169; Copyright 2018-2021, David.<br/>\n'
' \n'
' &#169; Copyright 2022-2025, Eve.'
) in content