Fix #8352: std domain: Failed to parse an option that starts with bracket

This commit is contained in:
Takeshi KOMIYA 2020-11-29 02:22:29 +09:00
parent e4bd3bd3dd
commit 6d24579f40
3 changed files with 29 additions and 1 deletions

View File

@ -70,6 +70,7 @@ Bugs fixed
* #8131: linkcheck: Use GET when HEAD requests cause Too Many Redirects, to * #8131: linkcheck: Use GET when HEAD requests cause Too Many Redirects, to
accommodate infinite redirect loops on HEAD accommodate infinite redirect loops on HEAD
* #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous * #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous
* #8352: std domain: Failed to parse an option that starts with bracket
Testing Testing
-------- --------

View File

@ -43,7 +43,7 @@ logger = logging.getLogger(__name__)
# RE for option descriptions # RE for option descriptions
option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=[]+)(=?\s*.*)') option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=]+)(=?\s*.*)')
# RE for grammar tokens # RE for grammar tokens
token_re = re.compile(r'`(\w+)`', re.U) token_re = re.compile(r'`(\w+)`', re.U)
@ -197,6 +197,11 @@ class Cmdoption(ObjectDescription):
location=signode) location=signode)
continue continue
optname, args = m.groups() optname, args = m.groups()
if optname.endswith('[') and args.endswith(']'):
# optional value surrounded by brackets (ex. foo[=bar])
optname = optname[:-1]
args = '[' + args
if count: if count:
signode += addnodes.desc_addname(', ', ', ') signode += addnodes.desc_addname(', ', ', ')
signode += addnodes.desc_name(optname, optname) signode += addnodes.desc_name(optname, optname)

View File

@ -91,6 +91,28 @@ def test_get_full_qualified_name():
assert domain.get_full_qualified_name(node) == 'ls.-l' assert domain.get_full_qualified_name(node) == 'ls.-l'
def test_cmd_option_with_optional_value(app):
text = ".. option:: -j[=N]"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (index,
[desc, ([desc_signature, ([desc_name, '-j'],
[desc_addname, '[=N]'])],
[desc_content, ()])]))
objects = list(app.env.get_domain("std").get_objects())
assert ('-j', '-j', 'cmdoption', 'index', 'cmdoption-j', 1) in objects
def test_cmd_option_starting_with_bracket(app):
text = ".. option:: [enable=]PATTERN"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (index,
[desc, ([desc_signature, ([desc_name, '[enable'],
[desc_addname, '=]PATTERN'])],
[desc_content, ()])]))
objects = list(app.env.get_domain("std").get_objects())
assert ('[enable', '[enable', 'cmdoption', 'index', 'cmdoption-arg-enable', 1) in objects
def test_glossary(app): def test_glossary(app):
text = (".. glossary::\n" text = (".. glossary::\n"
"\n" "\n"