From e51ee654bff555384425059ab60216d4e81fee3c Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 7 Mar 2013 14:10:26 +0000 Subject: [PATCH] Fix [ 3607029 ] traceback with embedded alias pointing to missing target. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk@7624 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 4 ++++ docutils/docutils/transforms/references.py | 10 ++++++---- docutils/test/test_transforms/test_hyperlinks.py | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 7f7babaf3..7f236c041 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -33,6 +33,10 @@ Changes Since 0.10 - 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``. diff --git a/docutils/docutils/transforms/references.py b/docutils/docutils/transforms/references.py index 05296ea1e..25c3e72f2 100644 --- a/docutils/docutils/transforms/references.py +++ b/docutils/docutils/transforms/references.py @@ -275,7 +275,8 @@ class IndirectHyperlinks(Transform): 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) @@ -391,15 +392,16 @@ class InternalTargets(Transform): """ 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 diff --git a/docutils/test/test_transforms/test_hyperlinks.py b/docutils/test/test_transforms/test_hyperlinks.py index caaef1014..6f4081ad9 100755 --- a/docutils/test/test_transforms/test_hyperlinks.py +++ b/docutils/test/test_transforms/test_hyperlinks.py @@ -374,6 +374,28 @@ An `anonymous embedded alias `__. . """], +# TODO: suppress the INFO message? +["""\ +An `embedded alias `_ with unknown reference. +""", +"""\ + + + An \n\ + + `embedded alias `_ + + with unknown reference. + + + Indirect hyperlink target "embedded alias" refers to target "alias", which does not exist. + + + Unknown target name: "alias". + + + Hyperlink target "embedded alias" is not referenced.\ +"""], ["""\ .. _target: -- 2.11.4.GIT