From: Vladimír Vondruš Date: Fri, 27 Apr 2018 14:56:31 +0000 (+0200) Subject: doxygen: don't crash when encountering sections with _1 in them. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=48e03c6be934cb2031e00c78db74b4e28eb161d4;p=blog.git doxygen: don't crash when encountering sections with _1 in them. --- diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index 29368de8..96105a4a 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -411,9 +411,15 @@ def parse_id(element: ET.Element) -> Tuple[str, str]: return base_url, id[i+2:] def extract_id_hash(state: State, element: ET.Element) -> str: - base_url, id = parse_id(element) - assert base_url == state.current_compound.url - return id + # Can't use parse_id() here as sections with _1 in it have it verbatim + # unescaped and mess up with the rindex(). OTOH, can't use this approach in + # parse_id() because for example enums can be present in both file and + # namespace documentation, having the base_url either the file one or the + # namespace one, depending on what's documented better. Ugh. See the + # contents_section_underscore_one test for a verification. + id = element.attrib['id'] + assert id.startswith(state.current_compound.url_base) + return id[len(state.current_compound.url_base)+2:] def fix_type_spacing(type: str) -> str: return type.replace('< ', '<').replace(' >', '>').replace(' &', '&').replace(' *', '*') @@ -1952,7 +1958,8 @@ def parse_xml(state: State, xml: str): # is for groups. compound.name = compounddef.find('title').text if compound.kind in ['page', 'group'] and compounddef.findtext('title') else compounddef.find('compoundname').text # Compound URL is ID, except for index page - compound.url = (compounddef.find('compoundname').text if compound.kind == 'page' else compound.id) + '.html' + compound.url_base = (compounddef.find('compoundname').text if compound.kind == 'page' else compound.id) + compound.url = compound.url_base + '.html' # Save current compound URL for search data building and ID extraction state.current_compound = compound compound.has_template_details = False diff --git a/doxygen/test/contents_section_underscore_one/Doxyfile b/doxygen/test/contents_section_underscore_one/Doxyfile new file mode 100644 index 00000000..ccb711b2 --- /dev/null +++ b/doxygen/test/contents_section_underscore_one/Doxyfile @@ -0,0 +1,13 @@ +INPUT = input.dox +QUIET = YES +GENERATE_HTML = NO +GENERATE_LATEX = NO +GENERATE_XML = YES +XML_PROGRAMLISTING = NO + +M_PAGE_FINE_PRINT = +M_THEME_COLOR = +M_LINKS_NAVBAR1 = +M_LINKS_NAVBAR2 = +M_SEARCH_DISABLED = YES + diff --git a/doxygen/test/contents_section_underscore_one/index.html b/doxygen/test/contents_section_underscore_one/index.html new file mode 100644 index 00000000..ae98d691 --- /dev/null +++ b/doxygen/test/contents_section_underscore_one/index.html @@ -0,0 +1,31 @@ + + + + + My Project + + + + + +
+
+
+
+
+

+ My Project +

+

A section

The section name has _1 in it, which is the same as the compound/section separator that Doxygen puts in. It shouldn't assert.

+
+
+
+
+ + diff --git a/doxygen/test/contents_section_underscore_one/input.dox b/doxygen/test/contents_section_underscore_one/input.dox new file mode 100644 index 00000000..bc7be0eb --- /dev/null +++ b/doxygen/test/contents_section_underscore_one/input.dox @@ -0,0 +1,6 @@ +/** @mainpage +@section section_1 A section + +The section name has `_1` in it, which is the same as the compound/section +separator that Doxygen puts in. It shouldn't assert. +*/ diff --git a/doxygen/test/test_contents.py b/doxygen/test/test_contents.py index 9c0387de..d6d578b1 100644 --- a/doxygen/test/test_contents.py +++ b/doxygen/test/test_contents.py @@ -169,3 +169,11 @@ class AutobriefHeading(IntegrationTestCase): def test(self): self.run_dox2html5(wildcard='namespaceNamespace.xml') self.assertEqual(*self.actual_expected_contents('namespaceNamespace.html')) + +class SectionUnderscoreOne(IntegrationTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'section_underscore_one', *args, **kwargs) + + def test(self): + self.run_dox2html5(wildcard='indexpage.xml') + self.assertEqual(*self.actual_expected_contents('index.html'))