From 59d655c435e7ca1a5e48cbbf9809d2553cc71d5d Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Tue, 30 Apr 2013 23:36:27 +0900 Subject: [PATCH] Fix: Combination of 'globaltoc.html' and hidden toctree cause exception. Closes #1157 --- CHANGES | 1 + sphinx/environment.py | 3 ++- tests/test_build_html.py | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 127abeed2..08493a851 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Features added Bugs fixed ---------- +* #1157: Combination of 'globaltoc.html' and hidden toctree cause exception. * Fix: 'make gettext' cause UnicodeDecodeError when templates contain utf-8 encoded string. diff --git a/sphinx/environment.py b/sphinx/environment.py index d8342c515..b27cbfed8 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -1049,7 +1049,8 @@ class BuildEnvironment: for toctreenode in doctree.traverse(addnodes.toctree): toctree = self.resolve_toctree(docname, builder, toctreenode, prune=True, **kwds) - toctrees.append(toctree) + if toctree: + toctrees.append(toctree) if not toctrees: return None result = toctrees[0] diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3890f6e1b..6b4a07df7 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -21,7 +21,7 @@ except ImportError: pygments = None from sphinx import __version__ -from util import test_root, remove_unicode_literals, gen_with_app +from util import test_root, remove_unicode_literals, gen_with_app, with_app from etree13 import ElementTree as ET @@ -344,3 +344,18 @@ def test_html(app): yield check_xpath, etree, fname, path, check check_static_entries(app.builder.outdir) + +@with_app(buildername='html', srcdir='(empty)', + confoverrides={'html_sidebars': {'*': ['globaltoc.html']}}, + ) +def test_html_with_globaltoc_and_hidden_toctree(app): + # issue #1157: combination of 'globaltoc.html' and hidden toctree cause + # exception. + (app.srcdir / 'contents.rst').write_text( + '\n.. toctree::' + '\n' + '\n.. toctree::' + '\n :hidden:' + '\n') + app.builder.build_all() +