diff --git a/csharp/PhoneNumbers.MetadataBuilder/Program.cs b/csharp/PhoneNumbers.MetadataBuilder/Program.cs index de33c088..fbd5c1e0 100644 --- a/csharp/PhoneNumbers.MetadataBuilder/Program.cs +++ b/csharp/PhoneNumbers.MetadataBuilder/Program.cs @@ -57,6 +57,12 @@ public static int Main(string[] args) try { return Run(args); } finally { mutex.ReleaseMutex(); } } + // Deliberately broad: this is the process-wide handler for a build-time tool, and the + // work it guards reaches XML parsing, file I/O and named-mutex code that between them + // can throw a dozen unrelated types. Nothing is swallowed — the full exception goes to + // stderr and the non-zero exit code fails the MSBuild target that invoked us — so + // narrowing this would only trade a readable one-line diagnostic for an unhandled- + // exception crash dump, with no change to whether the build fails. catch (Exception ex) { Console.Error.WriteLine($"PhoneNumbers.MetadataBuilder failed: {ex.Message}"); diff --git a/csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs b/csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs index 36c7da49..517c3c96 100644 --- a/csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs +++ b/csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs @@ -247,6 +247,11 @@ public void TestIsLatinLetter() Assert.True(PhoneNumberMatcher.IsLatinLetter('C')); Assert.True(PhoneNumberMatcher.IsLatinLetter('\u00C9')); Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0301')); // Combining acute accent + // One letter from each remaining accepted block, so every arm of the range test is + // exercised: these were the blocks no assertion reached. + Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0100')); // Latin Extended-A + Assert.True(PhoneNumberMatcher.IsLatinLetter('\u0180')); // Latin Extended-B + Assert.True(PhoneNumberMatcher.IsLatinLetter('\u1E00')); // Latin Extended Additional // Punctuation, digits and white-space are not considered "latin letters". Assert.False(PhoneNumberMatcher.IsLatinLetter(':')); Assert.False(PhoneNumberMatcher.IsLatinLetter('5')); diff --git a/csharp/PhoneNumbers/PhoneNumberMatcher.cs b/csharp/PhoneNumbers/PhoneNumberMatcher.cs index f44cfaf2..bb6e2acc 100644 --- a/csharp/PhoneNumbers/PhoneNumberMatcher.cs +++ b/csharp/PhoneNumbers/PhoneNumberMatcher.cs @@ -217,14 +217,15 @@ public static bool IsLatinLetter(char letter) // Combining marks are a subset of non-spacing-mark. if (!char.IsLetter(letter) && CharUnicodeInfo.GetUnicodeCategory(letter) != UnicodeCategory.NonSpacingMark) return false; - return - letter <= 0x007F // BASIC_LATIN - || letter >= 0x0080 && letter <= 0x00FF // LATIN_1_SUPPLEMENT - || letter >= 0x0100 && letter <= 0x017F // LATIN_EXTENDED_A - || letter >= 0x1E00 && letter <= 0x1EFF // LATIN_EXTENDED_ADDITIONAL - || letter >= 0x0180 && letter <= 0x024F // LATIN_EXTENDED_B - || letter >= 0x0300 && letter <= 0x036F // COMBINING_DIACRITICAL_MARKS - ; + // The Unicode blocks Java's isLatinLetter() accepts, expressed as the code point + // ranges that define them (C# has no Character.UnicodeBlock equivalent). + return letter is + <= '\u007F' // BASIC_LATIN + or (>= '\u0080' and <= '\u00FF') // LATIN_1_SUPPLEMENT + or (>= '\u0100' and <= '\u017F') // LATIN_EXTENDED_A + or (>= '\u1E00' and <= '\u1EFF') // LATIN_EXTENDED_ADDITIONAL + or (>= '\u0180' and <= '\u024F') // LATIN_EXTENDED_B + or (>= '\u0300' and <= '\u036F'); // COMBINING_DIACRITICAL_MARKS } private static bool IsInvalidPunctuationSymbol(char character)