Skip to content

Commit 4a2f5df

Browse files
committed
Merge branch '9299' into 4.x
2 parents 573db83 + e6d3adf commit 4a2f5df

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

sphinx/ext/intersphinx.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
305305
to_try.append((inventories.named_inventory[setname], full_qualified_name))
306306
for inventory, target in to_try:
307307
for objtype in objtypes:
308-
if objtype not in inventory or target not in inventory[objtype]:
308+
if objtype not in inventory:
309+
# Continue if there's nothing of this kind in the inventory
309310
continue
310-
proj, version, uri, dispname = inventory[objtype][target]
311+
if target in inventory[objtype]:
312+
# Case sensitive match, use it
313+
proj, version, uri, dispname = inventory[objtype][target]
314+
elif objtype == 'std:term':
315+
# Check for potential case insensitive matches for terms only
316+
target_lower = target.lower()
317+
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
318+
inventory[objtype].keys()))
319+
if insensitive_matches:
320+
proj, version, uri, dispname = inventory[objtype][insensitive_matches[0]]
321+
else:
322+
# No case insensitive match either, continue to the next candidate
323+
continue
324+
else:
325+
# Could reach here if we're not a term but have a case insensitive match.
326+
# This is a fix for terms specifically, but potentially should apply to
327+
# other types.
328+
continue
329+
311330
if '://' not in uri and node.get('refdoc'):
312331
# get correct path in case of subdirectories
313332
uri = path.join(relative_path(node['refdoc'], '.'), uri)

tests/test_ext_intersphinx.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ def test_missing_reference_pydomain(tempdir, app, status, warning):
196196
rn = missing_reference(app, app.env, node, contnode)
197197
assert rn.astext() == 'Foo.bar'
198198

199+
# term reference (normal)
200+
node, contnode = fake_node('std', 'term', 'a term', 'a term')
201+
rn = missing_reference(app, app.env, node, contnode)
202+
assert rn.astext() == 'a term'
203+
204+
# term reference (case insensitive)
205+
node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
206+
rn = missing_reference(app, app.env, node, contnode)
207+
assert rn.astext() == 'A TERM'
208+
199209

200210
def test_missing_reference_stddomain(tempdir, app, status, warning):
201211
inv_file = tempdir / 'inventory'

0 commit comments

Comments
 (0)