From 07de0ed10b4a24f6850702bf075d3cdbb5cf83d3 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 18 Feb 2018 22:55:58 +0900 Subject: [PATCH] Fix #4641: A external link in TOC cannot contain "?" with ``:glob:`` option --- CHANGES | 1 + sphinx/directives/other.py | 12 ++++++------ tests/roots/test-toctree-glob/index.rst | 1 + tests/test_environment_toctree.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 7f841a5d0..fcbd409f5 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,7 @@ Bugs fixed * #4630: Have order on msgids in sphinx.pot deterministic * #4563: autosummary: Incorrect end of line punctuation detection * #4577: Enumerated sublists with explicit start with wrong number +* #4641: A external link in TOC cannot contain "?" with ``:glob:`` option Testing -------- diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 6c1a4cd86..f04e429c2 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -73,7 +73,9 @@ class TocTree(Directive): for entry in self.content: if not entry: continue - if glob and ('*' in entry or '?' in entry or '[' in entry): + # look for explicit titles ("Some Title ") + explicit = explicit_title_re.match(entry) + if glob and ('*' in entry or '?' in entry or '[' in entry) and not explicit: patname = docname_join(env.docname, entry) docnames = sorted(patfilter(all_docnames, patname)) for docname in docnames: @@ -85,11 +87,9 @@ class TocTree(Directive): 'toctree glob pattern %r didn\'t match any documents' % entry, line=self.lineno)) else: - # look for explicit titles ("Some Title ") - m = explicit_title_re.match(entry) - if m: - ref = m.group(2) - title = m.group(1) + if explicit: + ref = explicit.group(2) + title = explicit.group(1) docname = ref else: ref = docname = entry diff --git a/tests/roots/test-toctree-glob/index.rst b/tests/roots/test-toctree-glob/index.rst index a3c198ce3..3fda0618b 100644 --- a/tests/roots/test-toctree-glob/index.rst +++ b/tests/roots/test-toctree-glob/index.rst @@ -12,6 +12,7 @@ normal order bar/* baz qux/index + hyperref reversed order ------------- diff --git a/tests/test_environment_toctree.py b/tests/test_environment_toctree.py index 26334858b..ad97b94fb 100644 --- a/tests/test_environment_toctree.py +++ b/tests/test_environment_toctree.py @@ -113,7 +113,7 @@ def test_glob(app): maxdepth=-1, numbered=0, includefiles=includefiles, entries=[(None, 'foo'), (None, 'bar/index'), (None, 'bar/bar_1'), (None, 'bar/bar_2'), (None, 'bar/bar_3'), (None, 'baz'), - (None, 'qux/index')]) + (None, 'qux/index'), ('hyperref', 'https://sphinx-doc.org/?q=sphinx')]) assert_node(toctree[0][1][1], [list_item, ([compact_paragraph, reference, "reversed order"], [bullet_list, addnodes.toctree])]) # [0][1][1][1][0]