From e1e15d7a8c31b92a18a36b963d2eae0e73edcda4 Mon Sep 17 00:00:00 2001 From: Jonas Nyrup Date: Sun, 4 Sep 2022 15:03:02 +0200 Subject: [PATCH] Use InvariantCulture when doing case-insensitive matches --- .../Primitives/StringWildcardMatchingValidator.cs | 2 +- .../Primitives/StringComparisonSpecs.cs | 8 ++++++++ docs/_pages/releases.md | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Src/FluentAssertions/Primitives/StringWildcardMatchingValidator.cs b/Src/FluentAssertions/Primitives/StringWildcardMatchingValidator.cs index b2e66466e0..e39c38d37f 100644 --- a/Src/FluentAssertions/Primitives/StringWildcardMatchingValidator.cs +++ b/Src/FluentAssertions/Primitives/StringWildcardMatchingValidator.cs @@ -30,7 +30,7 @@ protected override void ValidateAgainstMismatch() private bool IsMatch() { - RegexOptions options = IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None; + RegexOptions options = IgnoreCase ? (RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) : RegexOptions.None; string input = CleanNewLines(Subject); string pattern = ConvertWildcardToRegEx(CleanNewLines(Expected)); diff --git a/Tests/FluentAssertions.Specs/Primitives/StringComparisonSpecs.cs b/Tests/FluentAssertions.Specs/Primitives/StringComparisonSpecs.cs index 15b38417be..affc78c8fc 100644 --- a/Tests/FluentAssertions.Specs/Primitives/StringComparisonSpecs.cs +++ b/Tests/FluentAssertions.Specs/Primitives/StringComparisonSpecs.cs @@ -325,6 +325,14 @@ public void When_formatting_the_context_it_should_ignore_culture() .WithMessage("*1.234*", "it should always use . as decimal separator"); } + [CulturedTheory("tr-TR")] + [MemberData(nameof(EquivalencyData))] + public void Matching_strings_for_equivalence_ignores_the_culture(string subject, string expected) + { + // Assert + subject.Should().MatchEquivalentOf(expected); + } + public static IEnumerable EquivalencyData { get diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index a0bd78905d..eb74a03506 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -17,6 +17,7 @@ sidebar: ### Fixes * Fixed `For`/`Exclude` not excluding properties in objects in a collection - [#1953](https://github.com/fluentassertions/fluentassertions/pull/1953) +* Changed `MatchEquivalentOf` to use `CultureInfo.InvariantCulture` instead of `CultureInfo.CurrentCulture` - [#1985](https://github.com/fluentassertions/fluentassertions/pull/1985). ## 6.7.0