-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# IsSubsequenceOf throws IndexOutOfRangeException #35598
Comments
EDIT: nevermind, I missed the actual purpose of this code. It would not be possible to use the built-in methods without reading
public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true)
{
var compareAs = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
return text.IndexOf(instance, compareAs) >= 0;
} (adapted from Remarks at https://docs.microsoft.com/en-us/dotnet/api/system.string.contains) |
@raulsntos I can confirm that your proposed solution resolves the issue.
The need to discuss the best fix first is for adding new engine features, which are now done separately in the Godot Proposals repository. If you already have a fix for a bug, as you have here, feel free to submit a PR. It will be discussed in the PR if necessary. See the PR workflow documentation for how to submit a PR if you're unsure. |
Closes godotengine#35598 (cherry picked from commit 4b79ef5)
Godot version:
Godot_v3.2-rc3_mono_x11_64
OS/device including version:
Linux (Pop OS 19.10) but should affect every platform
Issue description:
Steps to reproduce:
Call method
IsSubsequenceOf
orIsSubsequenceOfI
Minimal reproduction project:
SubsequenceBug.zip
This project includes SceneBUG where the code is using the engine methods and fails and SceneFIX where I implemented the possible solution described below.
In StringExtensions.cs lines 477 and 494 it tries to access a character in the strings until finding 0 which never happens, instead eventually
source
ortarget
will be bigger than the length of the strings which results inIndexOutOfRangeException
:godot/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
Lines 464 to 502 in 12482bf
I could create a PR fixing this but according to CONTRIBUTING.md I'm supposed to open an issue first to discuss the best fix for this bug, this is my first time contributing to Godot.
About fixing this, I thought that we could check the length of the string instead like so:
The text was updated successfully, but these errors were encountered: