From 1e70292320dae0fdc9ffc974648231eb4fb992ce Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Tue, 20 Oct 2026 18:46:13 +0100 Subject: [PATCH] [3.11] Add Sphinx markup for CVEs in Changelog entries (GH-159415) (GH-159913) (cherry picked from commit aa5b0ed2b428e796fbf8b1228cd76549ab268f83) Co-authored-by: Stan Ulbrych (cherry picked from commit 44a2c1a5d9f460f8f5f1c09287a293e77ac3aa2e) --- Doc/conf.py | 6 ++++++ Doc/tools/extensions/pyspecific.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Doc/conf.py b/Doc/conf.py index 7554b64e3cc4102..2ce143240e31d8d 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -24,6 +24,7 @@ 'pyspecific', 'sphinx.ext.coverage', 'sphinx.ext.doctest', + 'sphinx.ext.extlinks', ] # Skip if downstream redistributors haven't installed it @@ -500,6 +501,11 @@ refcount_file = 'data/refcounts.dat' stable_abi_file = 'data/stable_abi.dat' +# sphinx.ext.extlinks config +extlinks = { + 'cve': ('https://www.cve.org/CVERecord?id=CVE-%s', 'CVE-%s'), +} + # sphinxext-opengraph config ogp_site_url = 'https://docs.python.org/3/' ogp_site_name = 'Python documentation' diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index c71ad641d7c07b4..80982d566513b18 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -496,6 +496,7 @@ def run(self): issue_re = re.compile('(?:[Ii]ssue #|bpo-)([0-9]+)', re.I) gh_issue_re = re.compile('(?:gh-issue-|gh-)([0-9]+)', re.I) +cve_re = re.compile('CVE-([0-9]{4}-[0-9]{4,})', re.I) whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$") @@ -525,6 +526,7 @@ def run(self): content = issue_re.sub(r':issue:`\1`', content) # Fallback handling for the GitHub issue content = gh_issue_re.sub(r':gh:`\1`', content) + content = cve_re.sub(r':cve:`\1`', content) content = whatsnew_re.sub(r'\1', content) # remove first 3 lines as they are the main heading lines = ['.. default-role:: obj', ''] + content.splitlines()[3:]