Skip to content

Commit fea14ad

Browse files
committed
fix: prevent ArgumentOutOfRangeException in XRefHrefFixer.FixPackage
P0.3 — MethodNameRegex requires '(' in the name to match. When it does not match, Groups[1].Value is "" causing name.Substring(0, 0) = "" and uid.IndexOf("") == 0, so uid.Substring(0, -1) threw. Fix: fall back to using name directly when the regex does not match. P0.2 — IndexOf returns -1 when methodName or name is not present in uid, making Substring(0, -2) throw. Fix: guard both call sites; when the name is absent from uid, return a best-effort href using the uid directly with non-word characters replaced by underscores. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
1 parent 9e2743f commit fea14ad

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

UnityXrefMaps/XRefHrefFixer.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,32 @@ private static string FixPackage(string apiUrl, string name, string type, string
3939
case "M":
4040
Match methodNameMatch = MethodNameRegex().Match(name);
4141

42-
string methodName = name.Substring(0, methodNameMatch.Groups[1].Value.Length);
42+
// P0.3: regex requires '(' — fall back to the full name when it is absent
43+
string methodName = methodNameMatch.Success
44+
? name.Substring(0, methodNameMatch.Groups[1].Value.Length)
45+
: name;
4346

44-
classFullName = uid.Substring(0, uid.IndexOf(methodName) - 1);
47+
// P0.2: IndexOf returns -1 when methodName is not present in uid
48+
int methodIdx = uid.IndexOf(methodName);
49+
if (methodIdx < 0)
50+
{
51+
return $"{apiUrl}{NonWordCharRegex().Replace(uid, "_")}.html";
52+
}
53+
54+
classFullName = uid.Substring(0, methodIdx - 1);
4555

4656
return $"{apiUrl}{classFullName}.html#{NonWordCharRegex().Replace(uid, "_")}";
4757
case "P":
4858
case "F":
4959
default:
50-
classFullName = uid.Substring(0, uid.IndexOf(name) - 1);
60+
// P0.2: IndexOf returns -1 when name is not present in uid
61+
int nameIdx = uid.IndexOf(name);
62+
if (nameIdx < 0)
63+
{
64+
return $"{apiUrl}{NonWordCharRegex().Replace(uid, "_")}.html";
65+
}
66+
67+
classFullName = uid.Substring(0, nameIdx - 1);
5168

5269
return $"{apiUrl}{classFullName}.html#{NonWordCharRegex().Replace(uid, "_")}";
5370
}

0 commit comments

Comments
 (0)