Skip to content

Commit fd6a58f

Browse files
CSHARP-2948: Check uses of string.Normalize in SaslPrepHelper when targetting netstandard2.0 (mongodb#516)
1 parent b6843a6 commit fd6a58f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/MongoDB.Driver.Core/Core/Authentication/SaslPrepHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ private static string SaslPrep(string str, bool allowUnassigned)
103103

104104
var mappedString = new string(chars.Take(length).ToArray());
105105
// 2. Normalize
106-
#if NET452
107-
var normalized = mappedString.Normalize(NormalizationForm.FormKC);
108-
#else
109-
// String normalization step in the .NET Standard version of the driver is skipped due to a lack of a string
106+
#if NETSTANDARD1_5
107+
// String normalization step in the .NET Standard 1.5 version of the driver is skipped due to a lack of a string
110108
// normalization function.
111109
var normalized = mappedString;
110+
#else
111+
var normalized = mappedString.Normalize(NormalizationForm.FormKC);
112112
#endif
113113
var containsRandALCat = false;
114114
var containsLCat = false;

tests/MongoDB.Driver.Core.Tests/Core/Authentication/SaslPrepHelperTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ namespace MongoDB.Driver.Core.Authentication
2626
/// </summary>
2727
public class SaslPrepHelperTests
2828
{
29-
// Currently, we only support SaslPrep in .NET Framework due to a lack of a string normalization function in
30-
// .NET Standard
31-
#if NET452
3229
[Fact]
3330
public void SaslPrepQuery_accepts_undefined_codepoint()
3431
{
@@ -52,6 +49,8 @@ public void SaslPrepStored_maps_space_equivalents_to_space(string expected, stri
5249
SaslPrepHelper.SaslPrepStored(input).Should().Be(expected);
5350
}
5451

52+
#if !NETCOREAPP1_1
53+
// Normalization is not supported in netstandard 1.5 due to a lack of a string normalization function.
5554
[Theory]
5655
[ParameterAttributeData]
5756
[InlineData("IX", "\u2168")] // "IX", Roman numeral nine
@@ -62,6 +61,7 @@ public void SaslPrepStored_returns_expected_output_when_passed_nonNormalized_str
6261
{
6362
SaslPrepHelper.SaslPrepStored(nonNormalizedStr).Should().Be(expected);
6463
}
64+
#endif
6565

6666
[Theory]
6767
[ParameterAttributeData]
@@ -80,8 +80,11 @@ public void SaslPrepStored_returns_expected_output_when_passed_partially_SaslPre
8080
[InlineData("user", "user")]
8181
[InlineData("user=", "user=")]
8282
[InlineData("USER", "USER")]
83+
#if !NETCOREAPP1_1
84+
// Normalization is not supported in netstandard 1.5 due to a lack of a string normalization function.
8385
[InlineData("a", "\u00AA")]
8486
[InlineData("IX", "\u2168")]
87+
#endif
8588
public void SaslPrepStored_returns_expected_output_when_passed_Rfc4013_examples(string expected, string input)
8689
{
8790
SaslPrepHelper.SaslPrepStored(input).Should().Be(expected);
@@ -117,7 +120,6 @@ public void SaslPrepStored_throws_exception_when_passed_an_undefined_codepoint()
117120
exception.Should().BeOfType<ArgumentException>();
118121
exception.Message.Should().Be("Character at position 3 is unassigned");
119122
}
120-
#endif
121123

122124
private static readonly Lazy<int> _unassignedCodePoint = new Lazy<int>(FindUnassignedCodePoint);
123125

0 commit comments

Comments
 (0)