diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 0797a7c7c..4795d1ae2 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -305,9 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref, to_try.append((inventories.named_inventory[setname], full_qualified_name)) for inventory, target in to_try: for objtype in objtypes: - if objtype not in inventory or target not in inventory[objtype]: + if objtype not in inventory: + # Continue if there's nothing of this kind in the inventory continue - proj, version, uri, dispname = inventory[objtype][target] + if target in inventory[objtype]: + # Case sensitive match, use it + proj, version, uri, dispname = inventory[objtype][target] + elif objtype == 'std:term': + # Check for potential case insensitive matches for terms only + target_lower = target.lower() + insensitive_matches = list(filter(lambda k: k.lower() == target_lower, + inventory[objtype].keys())) + if insensitive_matches: + proj, version, uri, dispname = inventory[objtype][insensitive_matches[0]] + else: + # No case insensitive match either, continue to the next candidate + continue + else: + # Could reach here if we're not a term but have a case insensitive match. + # This is a fix for terms specifically, but potentially should apply to + # other types. + continue + if '://' not in uri and node.get('refdoc'): # get correct path in case of subdirectories uri = path.join(relative_path(node['refdoc'], '.'), uri) diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py index 875f14346..28b5e63b1 100644 --- a/tests/test_ext_intersphinx.py +++ b/tests/test_ext_intersphinx.py @@ -196,6 +196,16 @@ def test_missing_reference_pydomain(tempdir, app, status, warning): rn = missing_reference(app, app.env, node, contnode) assert rn.astext() == 'Foo.bar' + # term reference (normal) + node, contnode = fake_node('std', 'term', 'a term', 'a term') + rn = missing_reference(app, app.env, node, contnode) + assert rn.astext() == 'a term' + + # term reference (case insensitive) + node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM') + rn = missing_reference(app, app.env, node, contnode) + assert rn.astext() == 'A TERM' + def test_missing_reference_stddomain(tempdir, app, status, warning): inv_file = tempdir / 'inventory'