Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,30 @@ public void TestNormaliseReplaceAlphaCharacters()
PhoneNumberUtil.Normalize(inputNumber));
}

[Fact]
public void TestNormaliseStripAlphaCharactersWithLineTerminators()
{
// Java's VALID_ALPHA_PHONE_PATTERN uses dot without DOTALL and matches the whole input.
foreach (var separator in new[] { "\n", "\r", "\r\n", "\u0085", "\u2028", "\u2029" })
{
foreach (var input in new[]
{
separator + "1800FLOWERS",
"1800F" + separator + "LOWERS",
"1800FLOWERS" + separator,
})
{
Assert.Equal("1800", PhoneNumberUtil.Normalize(input));
}
}

// Other whitespace is accepted by Java's dot and must not disable vanity conversion.
foreach (var separator in new[] { " ", "\t", "\v", "\f" })
{
Assert.Equal("18003569377", PhoneNumberUtil.Normalize("1800F" + separator + "LOWERS"));
}
}

[Fact]
public void TestNormaliseOtherDigits()
{
Expand Down
8 changes: 8 additions & 0 deletions csharp/PhoneNumbers/PhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ private static bool IsValidAlphaPhone(StringBuilder number)
{
var lower = number[i] | 0x20;
if ((uint)(lower - 'a') <= 'z' - 'a' && ++alpha == 3)
{
// Java's normalization pattern matches the whole input without DOTALL.
for (var j = 0; j < number.Length; j++)
{
if (number[j] is '\n' or '\r' or '\u0085' or '\u2028' or '\u2029')
return false;
}
return true;
}
}
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion csharp/PhoneNumbers/PhoneNumberUtil.net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ private static bool IsValidAlphaPhone(string number)
var lower = number[i] | 0x20;
if ((uint)(lower - 'a') <= 'z' - 'a' && ++alpha == 3)
{
return true;
// Java's normalization pattern matches the whole input without DOTALL.
return number.AsSpan().IndexOfAny("\n\r\u0085\u2028\u2029") < 0;
}
}

Expand Down
Loading