@@ -305,19 +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- # Special case handling for term to search in a case insensitive fashion
309- if objtype == 'std:term' and objtype in inventory :
310- cased_keys = {k .lower (): k for k in inventory [objtype ].keys ()}
311- if target .lower () in cased_keys :
312- corrected_target = cased_keys [target .lower ()]
313- proj , version , uri , dispname = inventory [objtype ][corrected_target ]
308+ if objtype not in inventory :
309+ # Continue if there's nothing of this kind in the inventory
310+ continue
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 ]]
314321 else :
322+ # No case insensitive match either, continue to the next candidate
315323 continue
316324 else :
317- # Default behaviour pre-patch
318- if objtype not in inventory or target not in inventory [objtype ]:
319- continue
320- proj , version , uri , dispname = inventory [objtype ][target ]
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+
321330 if '://' not in uri and node .get ('refdoc' ):
322331 # get correct path in case of subdirectories
323332 uri = path .join (relative_path (node ['refdoc' ], '.' ), uri )
0 commit comments