-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
StringSegment IndexOf behavior #53727
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@gfoidl @tarekgh @davidfowl (You reviewed/commented PR #46432) |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsDescriptionWorking on reopening PR for #45021 (first one was closed due to inactivity) First: runtime/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs Lines 519 to 529 in 911640b
runtime/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs Lines 457 to 467 in 911640b
Anyway, exception will be thrown in Span<T>.Slice method (exception message will be a little different), but I don't think this is by design 😄 Second: public static void Main(string[] args)
{
StringSegment segment = new StringSegment("12345", 0, 1);
var index = segment.IndexOfAny(new[] { '5' }, 2, 3);
Console.WriteLine(index); // Prints 4
} I believe that correct value here should be -1, am I missing something? Regression?Fixes will be breaking changes, but for the original issue (#45021) it was ok #46432 (comment)
|
You are right. In #53463 (comment) it was similar, and the argument validation was kept (to throw the correct exception with the right paramName). |
Could you please open a new PR if it is handy? Thanks! |
Very weird. I tried testing with My guess for why I also tested |
Description
Working on reopening PR for #45021 (first one was closed due to inactivity)
Found a few more strange behaviors
First:
There is no check for the right bound in
IndexOf
like in theIndexOfAny
IndexOfAny
:runtime/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs
Lines 519 to 529 in 911640b
IndexOf
:runtime/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs
Lines 457 to 467 in 911640b
Anyway, exception will be thrown in Span<T>.Slice method (exception message will be a little different), but I don't think this is by design 😄
Second:
Check for the right bound above (
IndexOfAny
) is quite weird, it allows to get index from original stringExample:
I believe that correct value here should be -1, am I missing something?UPD: OutOfRangeException should be thrown
So it seems like
Buffer.Length
have to be replaced withLength
propertyRegression?
Fixes will be breaking changes, but for the original issue (#45021) it was ok #46432 (comment)
The text was updated successfully, but these errors were encountered: