From 47ceb61deea007d4b0d9209c78cc721dd0a14e7a Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 6 Nov 2020 17:45:51 -0800 Subject: [PATCH 1/3] lastindexof breaking change --- docs/core/compatibility/3.1-5.0.md | 5 ++ docs/core/compatibility/corefx.md | 5 ++ ...ndexof-improved-handing-of-empty-values.md | 59 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index ccbd4525186c9..b93ac0db346e2 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -215,6 +215,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v ## Core .NET libraries +- [LastIndexOf has improved handling of empty search strings](#lastindexof-has-improved-handling-of-empty-search-strings) - [Global assembly cache APIs are obsolete](#global-assembly-cache-apis-are-obsolete) - [Remoting APIs are obsolete](#remoting-apis-are-obsolete) - [Most code access security APIs are obsolete](#most-code-access-security-apis-are-obsolete) @@ -241,6 +242,10 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v - [CounterSet.CreateCounterSetInstance now throws InvalidOperationException if instance already exist](#countersetcreatecountersetinstance-now-throws-invalidoperationexception-if-instance-already-exists) - [Microsoft.DotNet.PlatformAbstractions package removed](#microsoftdotnetplatformabstractions-package-removed) +[!INCLUDE [lastindexof-improved-handing-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md)] + +*** + [!INCLUDE [globalassemblycache-property-obsolete](../../../includes/core-changes/corefx/5.0/global-assembly-cache-apis-obsolete.md)] *** diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 2da4158f9a952..3e032a5fb7a1b 100644 --- a/docs/core/compatibility/corefx.md +++ b/docs/core/compatibility/corefx.md @@ -11,6 +11,7 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | :-: | +| [LastIndexOf has improved handling of empty search strings](#lastindexof-has-improved-handling-of-empty-search-strings) | 5.0 | | [Global assembly cache APIs are obsolete](#global-assembly-cache-apis-are-obsolete) | 5.0 | | [Remoting APIs are obsolete](#remoting-apis-are-obsolete) | 5.0 | | [Most code access security APIs are obsolete](#most-code-access-security-apis-are-obsolete) | 5.0 | @@ -57,6 +58,10 @@ The following breaking changes are documented on this page: ## .NET 5.0 +[!INCLUDE [lastindexof-improved-handing-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md)] + +*** + [!INCLUDE [remoting-apis-obsolete](../../../includes/core-changes/corefx/5.0/remoting-apis-obsolete.md)] *** diff --git a/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md b/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md new file mode 100644 index 0000000000000..6ee9472b5211f --- /dev/null +++ b/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md @@ -0,0 +1,59 @@ +### LastIndexOf has improved handling of empty search strings + + and related APIs now return correct values when searching for a zero-length (or zero-length equivalent) substring within a larger string. + +#### Change description + +In .NET Framework and .NET Core 1.0 - 3.1, and related APIs might return an incorrect value when the caller searches for a zero-length substring. + +```csharp +Console.WriteLine("Hello".LastIndexOf("")); // prints '4' (incorrect) + +ReadOnlySpan span = "Hello"; +Console.WriteLine(span.LastIndexOf("")); // prints '0' (incorrect) +``` + +Starting with .NET 5.0, these APIs return the correct value for `LastIndexOf`. + +```csharp +Console.WriteLine("Hello".LastIndexOf("")); // prints '5' (correct) + +ReadOnlySpan span = "Hello"; +Console.WriteLine(span.LastIndexOf("")); // prints '5' (correct) +``` + +In these examples, `5` is the correct answer because `"Hello".Substring(5)` and `"Hello".AsSpan().Slice(5)` both produce an empty string, which is trivially equal to the empty substring that is sought. + +#### Reason for change + +This change was part of an overall bug fixing effort around string handling for .NET 5. It also helps unify our behavior between Windows and non-Windows platforms. For more information, see [dotnet/runtime#13383](https://github.com/dotnet/runtime/issue/13383) and [dotnet/runtime##13382](https://github.com/dotnet/runtime/issue/13382). + +#### Version introduced + +5.0 + +#### Recommended action + +You don't need to take any action. The .NET 5.0 runtime provides the new behaviors automatically. + +There is no compatibility switch to restore the old behavior. + +#### Category + +Core .NET libraries + +#### Affected APIs + +- +- +- + + From 26a83f4a3df90e5809195e2485fdd7b6108b9832 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 6 Nov 2020 17:54:44 -0800 Subject: [PATCH 2/3] fix links --- .../corefx/5.0/lastindexof-improved-handing-of-empty-values.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md b/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md index 6ee9472b5211f..f32e59b2c72c3 100644 --- a/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md +++ b/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md @@ -26,7 +26,7 @@ In these examples, `5` is the correct answer because `"Hello".Substring(5)` and #### Reason for change -This change was part of an overall bug fixing effort around string handling for .NET 5. It also helps unify our behavior between Windows and non-Windows platforms. For more information, see [dotnet/runtime#13383](https://github.com/dotnet/runtime/issue/13383) and [dotnet/runtime##13382](https://github.com/dotnet/runtime/issue/13382). +This change was part of an overall bug fixing effort around string handling for .NET 5. It also helps unify our behavior between Windows and non-Windows platforms. For more information, see [dotnet/runtime#13383](https://github.com/dotnet/runtime/issues/13383) and [dotnet/runtime##13382](https://github.com/dotnet/runtime/issues/13382). #### Version introduced From c267e55da2ae102c05819bee07887fd7d5375340 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 9 Nov 2020 12:52:51 -0800 Subject: [PATCH 3/3] fix file name --- docs/core/compatibility/3.1-5.0.md | 2 +- docs/core/compatibility/corefx.md | 2 +- ...lues.md => lastindexof-improved-handling-of-empty-values.md} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename includes/core-changes/corefx/5.0/{lastindexof-improved-handing-of-empty-values.md => lastindexof-improved-handling-of-empty-values.md} (100%) diff --git a/docs/core/compatibility/3.1-5.0.md b/docs/core/compatibility/3.1-5.0.md index b93ac0db346e2..f5055efa87549 100644 --- a/docs/core/compatibility/3.1-5.0.md +++ b/docs/core/compatibility/3.1-5.0.md @@ -242,7 +242,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v - [CounterSet.CreateCounterSetInstance now throws InvalidOperationException if instance already exist](#countersetcreatecountersetinstance-now-throws-invalidoperationexception-if-instance-already-exists) - [Microsoft.DotNet.PlatformAbstractions package removed](#microsoftdotnetplatformabstractions-package-removed) -[!INCLUDE [lastindexof-improved-handing-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md)] +[!INCLUDE [lastindexof-improved-handling-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handling-of-empty-values.md)] *** diff --git a/docs/core/compatibility/corefx.md b/docs/core/compatibility/corefx.md index 3e032a5fb7a1b..8d494fe9572fd 100644 --- a/docs/core/compatibility/corefx.md +++ b/docs/core/compatibility/corefx.md @@ -58,7 +58,7 @@ The following breaking changes are documented on this page: ## .NET 5.0 -[!INCLUDE [lastindexof-improved-handing-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md)] +[!INCLUDE [lastindexof-improved-handling-of-empty-values](../../../includes/core-changes/corefx/5.0/lastindexof-improved-handling-of-empty-values.md)] *** diff --git a/includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md b/includes/core-changes/corefx/5.0/lastindexof-improved-handling-of-empty-values.md similarity index 100% rename from includes/core-changes/corefx/5.0/lastindexof-improved-handing-of-empty-values.md rename to includes/core-changes/corefx/5.0/lastindexof-improved-handling-of-empty-values.md