From c41e746b7a9640e7fbc6d5bc86d40484996434cc Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 23 Feb 2018 23:05:48 +0900 Subject: [PATCH] Fix #4662: any refs with term targets crash when an ambiguity is encountered --- CHANGES | 2 ++ sphinx/transforms/post_transforms/__init__.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 565235519..84428ab7d 100644 --- a/CHANGES +++ b/CHANGES @@ -42,6 +42,8 @@ Bugs fixed * #4655: Fix incomplete localization strings in Polish * #4653: Fix error reporting for parameterless ImportErrors * #4664: Reading objects.inv fails again +* #4662: ``any`` refs with ``term`` targets crash when an ambiguity is + encountered Testing -------- diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py index e1f8260a3..952b972f7 100644 --- a/sphinx/transforms/post_transforms/__init__.py +++ b/sphinx/transforms/post_transforms/__init__.py @@ -135,10 +135,12 @@ class ReferencesResolver(SphinxTransform): if not results: return None if len(results) > 1: - nice_results = ' or '.join(':%s:`%s`' % (name, role["reftitle"]) - for name, role in results) + def stringify(name, node): + reftitle = node.get('reftitle', node.astext()) + return ':%s:`%s`' % (name, reftitle) + candidates = ' or '.join(stringify(name, role) for name, role in results) logger.warning(__('more than one target found for \'any\' cross-' - 'reference %r: could be %s'), target, nice_results, + 'reference %r: could be %s'), target, candidates, location=node) res_role, newnode = results[0] # Override "any" class with the actual role type to get the styling