diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-03-07 14:10:26 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-03-07 14:10:26 +0000 |
commit | c5a1ea27613ac7c286f48b6f0fda3b83d43fc8c2 (patch) | |
tree | 17503d23f2630e02900ca2eb6fb007430e6864f9 | |
parent | 610e75d12dccf4a107ad298d896519640b631a93 (diff) | |
download | docutils-c5a1ea27613ac7c286f48b6f0fda3b83d43fc8c2.tar.gz |
Fix [ 3607029 ] traceback with embedded alias pointing to missing target.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7624 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | HISTORY.txt | 4 | ||||
-rw-r--r-- | docutils/transforms/references.py | 10 | ||||
-rwxr-xr-x | test/test_transforms/test_hyperlinks.py | 22 |
3 files changed, 32 insertions, 4 deletions
diff --git a/HISTORY.txt b/HISTORY.txt index 7f7babaf3..7f236c041 100644 --- a/HISTORY.txt +++ b/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/transforms/references.py b/docutils/transforms/references.py index 05296ea1e..25c3e72f2 100644 --- a/docutils/transforms/references.py +++ b/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): <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 diff --git a/test/test_transforms/test_hyperlinks.py b/test/test_transforms/test_hyperlinks.py index caaef1014..6f4081ad9 100755 --- a/test/test_transforms/test_hyperlinks.py +++ b/test/test_transforms/test_hyperlinks.py @@ -374,6 +374,28 @@ An `anonymous embedded alias <redirect_>`__. . <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: |