Commits

Anonymous committed ece0cde

Fix [ 3607029 ] traceback with embedded alias pointing to missing target.

Comments (0)

Files changed (3)

docutils/HISTORY.txt

 
   - Apply [ 3599485 ] node source/line information for sphinx translation.
 
+* docutils/transforms/references.py
+
+  - Fix [ 3607029 ] traceback with embedded alias pointing to missing target.
+
 * docutils/utils/__init__.py
 
   - Fix [ 3596884 ] exception importing ``docutils.io``.

docutils/docutils/transforms/references.py

             reflist.extend(self.document.refnames.get(name, []))
         for id in target['ids']:
             reflist.extend(self.document.refids.get(id, []))
-        naming += '(id="%s")' % target['ids'][0]
+        if target['ids']:
+            naming += '(id="%s")' % target['ids'][0]
         msg = self.document.reporter.error(
               'Indirect hyperlink target %s refers to target "%s", %s.'
               % (naming, target['refname'], explanation), base_node=target)
             <target id="id1" name="direct internal">
         """
         for name in target['names']:
-            refid = self.document.nameids[name]
+            refid = self.document.nameids.get(name)
             reflist = self.document.refnames.get(name, [])
             if reflist:
                 target.note_referenced_by(name=name)
             for ref in reflist:
                 if ref.resolved:
                     continue
-                del ref['refname']
-                ref['refid'] = refid
+                if refid:
+                    del ref['refname']
+                    ref['refid'] = refid
                 ref.resolved = 1
 
 

docutils/test/test_transforms/test_hyperlinks.py

         .
     <target ids="redirect" names="redirect" refuri="spam.py">
 """],
+# TODO: suppress the INFO message?                                                          
+["""\
+An `embedded alias <alias_>`_ with unknown reference.
+""",
+"""\
+<document source="test data">
+    <paragraph>
+        An \n\
+        <problematic ids="id3" refid="id2">
+            `embedded alias <alias_>`_
+        <target names="embedded\ alias" refname="alias">
+         with unknown reference.
+    <system_message ids="id1" level="3" line="1" source="test data" type="ERROR">
+        <paragraph>
+            Indirect hyperlink target "embedded alias"  refers to target "alias", which does not exist.
+    <system_message backrefs="id3" ids="id2" level="3" line="1" source="test data" type="ERROR">
+        <paragraph>
+            Unknown target name: "alias".
+    <system_message level="1" line="1" source="test data" type="INFO">
+        <paragraph>
+            Hyperlink target "embedded alias" is not referenced.\
+"""],
 ["""\
 .. _target: