Skip to content

Commit

Permalink
Fix off-by-one string indexing in constraint checking
Browse files Browse the repository at this point in the history
Also change string comparison type to `StringComparison.Ordinal`, which
should be the correct type according to
https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings.
  • Loading branch information
al2me6 committed Aug 1, 2021
1 parent 3894ce1 commit d9e9264
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ModuleManager/Extensions/StringExtensions.cs
Expand Up @@ -30,7 +30,7 @@ public static bool Contains(this string str, string value, out int index)
if (str == null) throw new ArgumentNullException(nameof(str));
if (value == null) throw new ArgumentNullException(nameof(value));

index = str.IndexOf(value, StringComparison.CurrentCultureIgnoreCase);
index = str.IndexOf(value, StringComparison.Ordinal);
return index != -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ModuleManager/MMPatchLoader.cs
Expand Up @@ -1548,7 +1548,7 @@ public static bool CheckConstraints(ConfigNode node, string constraints)
string remainingConstraints = "";
if (constraints.Contains(":HAS[", out int hasStart))
{
hasStart += 4;
hasStart += 5;
remainingConstraints = constraints.Substring(hasStart, constraintList[0].LastIndexOf(']') - hasStart);
constraints = constraints.Substring(0, hasStart - 5);
}
Expand Down

0 comments on commit d9e9264

Please sign in to comment.