Repository: sloria/sphinx-issues

Issue:
cve and cwe roles override Sphinx’s built-in roles
Sphinx 8.1.0, [released yesterday](https://www.sphinx-doc.org/en/master/changes/index.html#release-8-1-0-released-oct-10-2024), has built-in support for the `:cve:` and `:cwe:` roles, which collides with the support for these roles built into sphinx-issues (added in #44 and #122/#123).

When loading the extension, there are now these warnings:
```
WARNING: while setting up extension sphinx_issues: role 'cve' is already registered, it will be overridden [app.add_role]
WARNING: while setting up extension sphinx_issues: role 'cwe' is already registered, it will be overridden [app.add_role]
```

Sphinx’s support was added in https://github.com/sphinx-doc/sphinx/pull/11781.

I noticed this because I run `sphinx-build` with `--fail-on-warning` (turn warnings into errors).

BTW, thanks a lot for the package, I wish sphinx itself would use it for their changelog ...!

Hints from issue comments:
@mscheltienne: Same issue.@sloria: Ah thanks for the heads up. Those roles should be removed from this package, then, with a note in the README about the official roles. PRs welcome!@sloria: 5.0.0 drops the cve and cwe roles@mscheltienne: Great, thanks!@marcelm: Perfect, thanks so much!

> PRs welcome!

No way I could have done it so fast :smile: 

Solution patch:
diff --git a/README.rst b/README.rst
index efa0e9b..8e7937b 100644
--- a/README.rst
+++ b/README.rst
@@ -105,12 +105,6 @@ Use the ``:commit:`` role to link to commits.
 
     Fixed in :commit:`6bb9124d5e9dbb2f7b52864c3d8af7feb1b69403`.
 
-Use the ``:cve:`` role to link to CVEs on https://cve.mitre.org.
-
-.. code-block:: rst
-
-    :cve:`CVE-2018-17175` - Addresses possible vulnerability when...
-
 .. code-block:: rst
 
     Thanks to :user:`bitprophet` for the idea!
@@ -129,12 +123,6 @@ It can be also used in combination with a list:
 
     Fix bad bug :issue:`123, (Duplicate) <199>`
 
-Use the ``:cwe:`` role to link to CWEs on https://cwe.mitre.org.
-
-.. code-block:: rst
-
-    :cwe:`CWE-787` - The software writes data past the end, or...
-
 Use the ``:pypi:`` role to link to PyPI on https://pypi.org.
 
 .. code-block:: rst
@@ -155,6 +143,11 @@ MIT licensed. See the bundled `LICENSE <https://github.com/sloria/sphinx-issues/
 Changelog
 *********
 
+5.0.0 (unreleased)
+------------------
+
+- Remove `:cwe:` and `:cve:` roles, as these are officially included in Sphinx>=8.1.0.
+
 4.1.0 (2024-04-14)
 ------------------
 
diff --git a/src/sphinx_issues/__init__.py b/src/sphinx_issues/__init__.py
index 748120c..8aac77d 100644
--- a/src/sphinx_issues/__init__.py
+++ b/src/sphinx_issues/__init__.py
@@ -8,27 +8,6 @@ from docutils import nodes, utils
 from sphinx.config import Config
 from sphinx.util.nodes import split_explicit_title
 
-
-def cve_role(name, rawtext, text, lineno, inliner, options=None, content=None):
-    """Sphinx role for linking to a CVE on https://cve.mitre.org.
-
-    Examples: ::
-
-        :cve:`CVE-2018-17175`
-
-    """
-    options = options or {}
-    content = content or []
-    has_explicit_title, title, target = split_explicit_title(text)
-
-    target = utils.unescape(target).strip()
-    title = utils.unescape(title).strip()
-    ref = f"https://cve.mitre.org/cgi-bin/cvename.cgi?name={target}"
-    text = title if has_explicit_title else target
-    link = nodes.reference(text=text, refuri=ref, **options)
-    return [link], []
-
-
 GITHUB_USER_RE = re.compile("^https://github.com/([^/]+)/([^/]+)/.*")
 
 
@@ -165,27 +144,6 @@ def _get_uri(
         ) from e
 
 
-def cwe_role(name, rawtext, text, lineno, inliner, options=None, content=None):
-    """Sphinx role for linking to a CWE on https://cwe.mitre.org.
-
-    Examples: ::
-
-        :cwe:`CWE-787`
-
-    """
-    options = options or {}
-    content = content or []
-    has_explicit_title, title, target = split_explicit_title(text)
-
-    target = utils.unescape(target).strip()
-    title = utils.unescape(title).strip()
-    number = target[4:]
-    ref = f"https://cwe.mitre.org/data/definitions/{number}.html"
-    text = title if has_explicit_title else target
-    link = nodes.reference(text=text, refuri=ref, **options)
-    return [link], []
-
-
 def pypi_role(name, rawtext, text, lineno, inliner, options=None, content=None):
     """Sphinx role for linking to a PyPI on https://pypi.org/.
 
@@ -402,8 +360,6 @@ def setup(app):
     app.add_role("pr", pr_role)
     app.add_role("user", user_role)
     app.add_role("commit", commit_role)
-    app.add_role("cve", cve_role)
-    app.add_role("cwe", cwe_role)
     app.add_role("pypi", pypi_role)
     return {
         "version": importlib.metadata.version("sphinx-issues"),


Test patch:
diff --git a/tests/test_sphinx_issues.py b/tests/test_sphinx_issues.py
index b2fa3e8..054900e 100644
--- a/tests/test_sphinx_issues.py
+++ b/tests/test_sphinx_issues.py
@@ -10,8 +10,6 @@ import sphinx.application
 
 from sphinx_issues import (
     commit_role,
-    cve_role,
-    cwe_role,
     issue_role,
     pr_role,
     pypi_role,
@@ -95,20 +93,6 @@ def inliner(app):
             "Steven Loria",
             "https://github.com/sponsors/sloria",
         ),
-        (
-            cve_role,
-            "cve",
-            "CVE-2018-17175",
-            "CVE-2018-17175",
-            "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-17175",
-        ),
-        (
-            cwe_role,
-            "cve",
-            "CWE-787",
-            "CWE-787",
-            "https://cwe.mitre.org/data/definitions/787.html",
-        ),
         (
             pypi_role,
             "pypi",