Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :cve: role for linking to CVEs on Mitre #44

Merged
merged 1 commit into from Sep 19, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Add :cve: role for linking to CVEs on Mitre

  • Loading branch information...
sloria committed Sep 19, 2018
commit 73b20904f00ed2c05f2e0cc51b2b727f49e5f153
@@ -79,6 +79,11 @@ MIT licensed. See the bundled `LICENSE <https://github.com/sloria/sphinx-issues/
Changelog
*********

1.1.0 (unreleased)
------------------

- Add ``:cve:`` role for linking to CVEs on https://cve.mitre.org.

1.0.0 (2018-07-14)
------------------

@@ -41,6 +41,26 @@ def user_role(name, rawtext, text, lineno, inliner, options=None, content=None):
return [link], []


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 = "https://cve.mitre.org/cgi-bin/cvename.cgi?name={0}".format(target)
text = title if has_explicit_title else target
link = nodes.reference(text=text, refuri=ref, **options)
return [link], []


class IssueRole(object):
def __init__(self, uri_config_option, format_kwarg, github_uri_template):
self.uri_config_option = uri_config_option
@@ -125,6 +145,7 @@ def setup(app):
app.add_role("issue", issue_role)
app.add_role("pr", pr_role)
app.add_role("user", user_role)
app.add_role("cve", cve_role)
return {
"version": __version__,
"parallel_read_safe": True,
@@ -8,7 +8,13 @@
from mock import Mock

from sphinx.application import Sphinx
from sphinx_issues import issue_role, user_role, pr_role, setup as issues_setup
from sphinx_issues import (
issue_role,
user_role,
pr_role,
cve_role,
setup as issues_setup,
)

import pytest

@@ -92,3 +98,11 @@ def test_pr_role(inliner):
assert link.astext() == "#42"
issue_url = "https://github.com/marshmallow-code/marshmallow/pull/42"
assert link.attributes["refuri"] == issue_url


def test_cve_role(inliner):
result = cve_role(name=None, rawtext="", text="CVE-2018-17175", lineno=None, inliner=inliner)
link = result[0][0]
assert link.astext() == "CVE-2018-17175"
issue_url = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-17175"
assert link.attributes["refuri"] == issue_url
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.