docs/qapidoc: support header-less freeform sections
authorJohn Snow <jsnow@redhat.com>
Mon, 24 Feb 2025 03:37:35 +0000 (22:37 -0500)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 4 Mar 2025 06:11:06 +0000 (07:11 +0100)
The code as written crashes when a free-form documentation block doesn't
start with a heading or subheading, for example:

| ##
| # Just text, no heading.
| ##

The code will attempt to use the `node` variable uninitialized. To fix,
create a generic block to insert the doc text into.

(This patch also removes a lingering pylint warning in the QAPIDoc
implementation that prevents getting a clean baseline to use for
forthcoming additions.)

Fixes: 43e0d14ee09a (docs/sphinx: fix extra stuff in TOC after freeform QMP sections)
Signed-off-by: John Snow <jsnow@redhat.com>
Message-ID: <20250224033741.222749-5-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Test updated to cover this]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
docs/sphinx/qapidoc.py
tests/qapi-schema/doc-good.json
tests/qapi-schema/doc-good.out

index 5f96b46270bbd1bd52e17cfff5c77ab79dde799c..5a4d7388b29b9a2487d6cf7b0a7fb6e848f96e3e 100644 (file)
@@ -421,6 +421,8 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
             node = self._start_new_heading(heading, len(leader))
             if text == '':
                 return
+        else:
+            node = nodes.container()
 
         self._parse_text_into_node(text, node)
         self._cur_doc = None
index f64bf38d8547f1e7486b8931344ea76ff79b576c..0a4f139f8352d097491d749a2ced37e5a0e6596d 100644 (file)
 # = Section
 ##
 
+##
+# Just text, no heading.
+##
+
 ##
 # == Subsection
 #
index ec277be91e92640fb07902f51635cdfe7e3a7b9b..0a9da3efdeb974f73472b99f6598d5985abeca03 100644 (file)
@@ -56,6 +56,9 @@ event EVT_BOXED Object
 doc freeform
     body=
 = Section
+doc freeform
+    body=
+Just text, no heading.
 doc freeform
     body=
 == Subsection