fix: prevent crash in XRefHrefFixer when a method or property name is not found#8
Open
NormandErwan wants to merge 2 commits into
Open
fix: prevent crash in XRefHrefFixer when a method or property name is not found#8NormandErwan wants to merge 2 commits into
NormandErwan wants to merge 2 commits into
Conversation
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
fea14ad to
fbff6ba
Compare
fbff6ba to
55a6f48
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 exampleName = "MyMethod"instead of"MyMethod()"— the regex fails and returns an empty string. The code then calleduid.IndexOf(""), which always returns0, and thenuid.Substring(0, 0 - 1)=uid.Substring(0, -1), which throwsArgumentOutOfRangeException.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
uidstring withIndexOf. 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"—IndexOfreturns-1. The code then calleduid.Substring(0, -1 - 1)=uid.Substring(0, -2), which throwsArgumentOutOfRangeException. The same crash happens with properties and fields.Fix: Check the result of
IndexOfbefore callingSubstring. When the name is not found, fall back to using the fulluidwith special characters replaced by underscores.Tests
Fix_PackageMethodWithNoParenthesesInName_DoesNotThrow— method with no(in its name must not throwFix_PackageMethodNameAbsentFromUid_DoesNotThrow— method name not found in uid must not throwFix_PackagePropertyNameAbsentFromUid_DoesNotThrow— property name not found in uid must not throwPR #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