chiark / gitweb /
doxygen: don't crash when encountering sections with _1 in them.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 27 Apr 2018 14:56:31 +0000 (16:56 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 27 Apr 2018 15:08:42 +0000 (17:08 +0200)
doxygen/dox2html5.py
doxygen/test/contents_section_underscore_one/Doxyfile [new file with mode: 0644]
doxygen/test/contents_section_underscore_one/index.html [new file with mode: 0644]
doxygen/test/contents_section_underscore_one/input.dox [new file with mode: 0644]
doxygen/test/test_contents.py

index 29368de88a3896b1c508ce85f5ec5ffdff8061e1..96105a4a12d9022db64c3f0f6570fff1cb0ae19b 100755 (executable)
@@ -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('&lt; ', '&lt;').replace(' &gt;', '&gt;').replace(' &amp;', '&amp;').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 (file)
index 0000000..ccb711b
--- /dev/null
@@ -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 (file)
index 0000000..ae98d69
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8" />
+  <title>My Project</title>
+  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+  <link rel="stylesheet" href="m-dark+doxygen.compiled.css" />
+  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+  <div class="m-container">
+    <div class="m-row">
+      <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Project</a>
+    </div>
+  </div>
+</nav></header>
+<main><article>
+  <div class="m-container m-container-inflatable">
+    <div class="m-row">
+      <div class="m-col-l-10 m-push-l-1">
+        <h1>
+          My Project
+        </h1>
+<section id="section_1"><h2><a href="#section_1">A section</a></h2><p>The section name has <code>_1</code> in it, which is the same as the compound/section separator that Doxygen puts in. It shouldn&#x27;t assert.</p></section>
+      </div>
+    </div>
+  </div>
+</article></main>
+</body>
+</html>
diff --git a/doxygen/test/contents_section_underscore_one/input.dox b/doxygen/test/contents_section_underscore_one/input.dox
new file mode 100644 (file)
index 0000000..bc7be0e
--- /dev/null
@@ -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.
+*/
index 9c0387deebed125f9548cf02c1b04c1d3cf9fad5..d6d578b1748d2ff46e84b0144beff1939865f66e 100644 (file)
@@ -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'))