diff options
author | Georg Brandl <georg@python.org> | 2014-01-10 22:04:03 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-01-10 22:04:03 +0100 |
commit | 4238b992b5e047c00a8a94df263e64fc8d1260db (patch) | |
tree | f27a79a92803277d22d465efaed3e28f3999aac1 | |
parent | 6df56547e6ce002a3ea190a69b708da13e7eb66d (diff) | |
download | sphinx-4238b992b5e047c00a8a94df263e64fc8d1260db.tar.gz |
Closes #933: Do not crash if an ``:option:`` value is malformed (contains spaces
but no option name).
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | sphinx/domains/std.py | 17 | ||||
-rw-r--r-- | tests/root/markup.txt | 1 | ||||
-rw-r--r-- | tests/test_build_html.py | 2 |
4 files changed, 19 insertions, 4 deletions
@@ -30,6 +30,9 @@ Bugs fixed * #932: autodoc: Do not crash if ``__doc__`` is not a string. +* #933: Do not crash if an ``:option:`` value is malformed (contains spaces + but no option name). + Documentation ------------- diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index ae67bf0e..50e519fa 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -190,17 +190,26 @@ class Program(Directive): class OptionXRefRole(XRefRole): innernodeclass = addnodes.literal_emphasis + def _split(self, text, refnode, env): + try: + program, target = re.split(' (?=-|--|/)', text, 1) + except ValueError: + env.warn_node('Malformed :option: %r, does not contain option ' + 'marker - or -- or /' % text, refnode) + return None, text + else: + program = ws_re.sub('-', program) + return program, target + def process_link(self, env, refnode, has_explicit_title, title, target): program = env.temp_data.get('std:program') if not has_explicit_title: if ' ' in title and not (title.startswith('/') or title.startswith('-')): - program, target = re.split(' (?=-|--|/)', title, 1) - program = ws_re.sub('-', program) + program, target = self._split(title, refnode, env) target = target.strip() elif ' ' in target: - program, target = re.split(' (?=-|--|/)', target, 1) - program = ws_re.sub('-', program) + program, target = self._split(target, refnode, env) refnode['refprogram'] = program return title, target diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 1fb20cf0..39a8ebc0 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -139,6 +139,7 @@ Adding \n to test unescaping. * :doc:`subdir/includes` * ``:download:`` is tested in includes.txt * :option:`Python -c option <python -c>` +* This used to crash: :option:`Python c option` Test :abbr:`abbr (abbreviation)` and another :abbr:`abbr (abbreviation)`. diff --git a/tests/test_build_html.py b/tests/test_build_html.py index d5b59e42..bd8c0730 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -42,6 +42,8 @@ http://www.python.org/logo.png reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png +%(root)s/markup.txt:142: WARNING: Malformed :option: u'Python c option', does \ +not contain option marker - or -- or / %(root)s/objects.txt:\\d*: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ http://sphinx-doc.org/domains.html |