Skip to content

fix: prevent crash in XRefHrefFixer when a method or property name is not found#8

Open
NormandErwan wants to merge 2 commits into
mainfrom
claude/fix-xrefhref-crashes
Open

fix: prevent crash in XRefHrefFixer when a method or property name is not found#8
NormandErwan wants to merge 2 commits into
mainfrom
claude/fix-xrefhref-crashes

Conversation

@NormandErwan
Copy link
Copy Markdown
Owner

@NormandErwan NormandErwan commented May 2, 2026

Summary

Two crashes in XRefHrefFixer.FixPackage() that occur with certain API members in Unity packages.

Method name has no parentheses

Problem: When building the href for a method, the code runs a regex to strip generic arguments from the display name and extract just the method name. The regex requires a ( character to match. When the display name has no parentheses — for example Name = "MyMethod" instead of "MyMethod()" — the regex fails and returns an empty string. The code then called uid.IndexOf(""), which always returns 0, and then uid.Substring(0, 0 - 1) = uid.Substring(0, -1), which throws ArgumentOutOfRangeException.

Fix: When the regex does not match, use the full display name directly instead of the empty string.

Method or property name not found in the uid

Problem: After extracting the method name, the code looks for it inside the uid string with IndexOf. If the extracted name does not appear in the uid — for example when the display name is "DifferentMethod()" but the uid is "MyNamespace.MyClass.ActualMethod"IndexOf returns -1. The code then called uid.Substring(0, -1 - 1) = uid.Substring(0, -2), which throws ArgumentOutOfRangeException. The same crash happens with properties and fields.

Fix: Check the result of IndexOf before calling Substring. When the name is not found, fall back to using the full uid with special characters replaced by underscores.

Tests

  • Fix_PackageMethodWithNoParenthesesInName_DoesNotThrow — method with no ( in its name must not throw
  • Fix_PackageMethodNameAbsentFromUid_DoesNotThrow — method name not found in uid must not throw
  • Fix_PackagePropertyNameAbsentFromUid_DoesNotThrow — property name not found in uid must not throw

PR #9 contains just the tests without the fix to confirm CI goes red; this PR (with the fix applied) should go green.

https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4

Three tests that crash before the fix is applied:

- Fix_PackageMethodWithNoParenthesesInName_DoesNotThrow:
  name has no '(' so MethodNameRegex fails to match, methodName becomes "",
  uid.IndexOf("") == 0, uid.Substring(0, -1) throws.

- Fix_PackageMethodNameAbsentFromUid_DoesNotThrow:
  methodName is not found in uid, IndexOf returns -1,
  uid.Substring(0, -2) throws.

- Fix_PackagePropertyNameAbsentFromUid_DoesNotThrow:
  property name is not found in uid, IndexOf returns -1,
  uid.Substring(0, -2) throws.

https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
@NormandErwan NormandErwan force-pushed the claude/fix-xrefhref-crashes branch from fea14ad to fbff6ba Compare May 3, 2026 19:38
@NormandErwan NormandErwan changed the title fix: prevent ArgumentOutOfRangeException in XRefHrefFixer.FixPackage (P0.2 & P0.3) fix: prevent crash in XRefHrefFixer when a method or property name is not found May 3, 2026
@NormandErwan NormandErwan force-pushed the claude/fix-xrefhref-crashes branch from fbff6ba to 55a6f48 Compare May 9, 2026 15:17
When the display name had no parentheses, MethodNameRegex failed and
returned an empty string, causing Substring(0, -1) to throw. When the
extracted method or property name was absent from the uid, IndexOf
returned -1, causing Substring(0, -2) to throw. Guard both paths and
return a safe fallback URL instead.

https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants