Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3be1de2
ci: allow manual dispatch of the CodeQL full-repo scan
twcclegg Aug 26, 2026
7b6c079
style: harden Path.Combine and simplify up-to-date checks in Metadata…
twcclegg Aug 26, 2026
582bbe5
style: LINQ filters and TryGetValue in MetadataFilter/PhoneNumberOffl…
twcclegg Aug 26, 2026
d102266
test: exception-safe enumerator disposal, LINQ selects, drop dead Str…
twcclegg Aug 26, 2026
f811725
test: use Assert.Throws instead of manual try/catch in TestParseField…
twcclegg Aug 26, 2026
d5ad5fd
test: use Assert.Throws instead of manual try/catch in TestBuildMetad…
twcclegg Aug 26, 2026
f0f23ac
test: readonly fields, TryGetValue, and LINQ selects in TestPhoneNumb…
twcclegg Aug 26, 2026
1619543
test: TryGetValue and LINQ select in TestBuildPrefixMapFromBin/TestEx…
twcclegg Aug 26, 2026
68cfbdd
Merge remote-tracking branch 'origin/main' into ci/codeql-manual-disp…
twcclegg Aug 26, 2026
6b9d540
style: map region codes via Select in GetExpectedCost
twcclegg Aug 26, 2026
d413a88
style: filter local-only lengths explicitly via Where
twcclegg Aug 26, 2026
f78732b
style: drop redundant int.GetHashCode() call in PhoneNumberMatch
twcclegg Aug 26, 2026
1e58744
style: ternary builder merges and drop redundant int.GetHashCode() calls
twcclegg Aug 26, 2026
263cf3a
style: drop always-true lower bound in IsLatinLetter's BASIC_LATIN check
twcclegg Aug 26, 2026
6b902ef
style: address remaining CodeQL findings in PhoneNumberUtil.cs
twcclegg Aug 26, 2026
f047ae6
fix: address CodeQL findings on PR's own fix commits
twcclegg Aug 26, 2026
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
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches: [ "main" ]
schedule:
- cron: '35 21 * * 0'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
24 changes: 6 additions & 18 deletions csharp/PhoneNumbers.MetadataBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private static int BuildGeocoding(string inputDir, string outputDir)
{
var countryCode = Path.GetFileNameWithoutExtension(txtPath);
var map = ParseAreaCodeText(txtPath);
var outPath = Path.Combine(outputDir, $"{lang}.{countryCode}");
var outPath = Path.Join(outputDir, Path.GetFileName($"{lang}.{countryCode}"));
using var gz = new GZipStream(File.Create(outPath), CompressionLevel.SmallestSize);
BuildPrefixMapFromBin.WriteAreaCodeMap(gz, map);
written++;
Expand Down Expand Up @@ -251,11 +251,7 @@ private static bool IsOutputUpToDate(string inputXml, string outputDir, string f
var existing = Directory.GetFiles(outputDir, filePrefix + "_*");
if (existing.Length == 0) return false;
var inputMTime = File.GetLastWriteTimeUtc(inputXml);
foreach (var file in existing)
{
if (File.GetLastWriteTimeUtc(file) < inputMTime) return false;
}
return true;
return !existing.Any(file => File.GetLastWriteTimeUtc(file) < inputMTime);
}

/// <summary>
Expand All @@ -267,17 +263,9 @@ private static bool IsGeocodingOutputUpToDate(string inputDir, string outputDir)
if (!Directory.Exists(outputDir)) return false;
var existing = Directory.GetFiles(outputDir);
if (existing.Length == 0) return false;
var newestInput = DateTime.MinValue;
foreach (var f in Directory.EnumerateFiles(inputDir, "*.txt", SearchOption.AllDirectories))
{
var t = File.GetLastWriteTimeUtc(f);
if (t > newestInput) newestInput = t;
}
foreach (var file in existing)
{
if (File.GetLastWriteTimeUtc(file) < newestInput) return false;
}
return true;
var newestInput = Directory.EnumerateFiles(inputDir, "*.txt", SearchOption.AllDirectories)
.Select(File.GetLastWriteTimeUtc).DefaultIfEmpty(DateTime.MinValue).Max();
return !existing.Any(file => File.GetLastWriteTimeUtc(file) < newestInput);
}

private static SortedDictionary<int, string> ParseAreaCodeText(string path)
Expand Down Expand Up @@ -348,7 +336,7 @@ private static int BuildPerRegion(
foreach (var metadata in metadataList)
{
var key = MakeFileNameKey(metadata, isAlternateFormatsMetadata);
var path = Path.Combine(outputDir, $"{filePrefix}_{key}");
var path = Path.Join(outputDir, Path.GetFileName($"{filePrefix}_{key}"));
using var gz = new GZipStream(File.Create(path), CompressionLevel.SmallestSize);
BuildMetadataFromBin.WriteMetadata(gz, metadata);
written++;
Expand Down
33 changes: 6 additions & 27 deletions csharp/PhoneNumbers.Test/TestBuildMetadataFromXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,8 @@ public void TestLoadInternationalFormatExpectsOnlyOnePattern()
var metadata = new PhoneMetadata.Builder();

// Should throw an exception as multiple intlFormats are provided.
try
{
BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement, "");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() =>
BuildMetadataFromXml.LoadInternationalFormat(metadata, numberFormatElement, ""));
}

[Fact]
Expand Down Expand Up @@ -247,15 +240,8 @@ public void TestLoadNationalFormatRequiresFormat()
var metadata = new PhoneMetadata.Builder();
var numberFormat = new NumberFormat.Builder();

try
{
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat);
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() =>
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat));
}

[Fact]
Expand All @@ -266,15 +252,8 @@ public void TestLoadNationalFormatExpectsExactlyOneFormat()
var metadata = new PhoneMetadata.Builder();
var numberFormat = new NumberFormat.Builder();

try
{
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat);
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() =>
BuildMetadataFromXml.LoadNationalFormat(metadata, numberFormatElement, numberFormat));
}

// Tests loadAvailableFormats().
Expand Down
8 changes: 4 additions & 4 deletions csharp/PhoneNumbers.Test/TestBuildPrefixMapFromBin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void TestAreaCodeMap_WriteAndRead_VerifiesIntegrity()
Assert.Equal(testMap.Count, deserializedMap.Count);
foreach (var kvp in testMap)
{
Assert.True(deserializedMap.ContainsKey(kvp.Key));
Assert.Equal(kvp.Value, deserializedMap[kvp.Key]);
Assert.True(deserializedMap.TryGetValue(kvp.Key, out var value));
Assert.Equal(kvp.Value, value);
}
}

Expand Down Expand Up @@ -93,8 +93,8 @@ public void TestTimezoneMap_WriteAndRead_VerifiesIntegrity()
Assert.Equal(testMap.Count, deserializedMap.Count);
foreach (var kvp in testMap)
{
Assert.True(deserializedMap.ContainsKey(kvp.Key));
Assert.Equal(kvp.Value, deserializedMap[kvp.Key]);
Assert.True(deserializedMap.TryGetValue(kvp.Key, out var value));
Assert.Equal(kvp.Value, value);
}
}

Expand Down
6 changes: 3 additions & 3 deletions csharp/PhoneNumbers.Test/TestExampleNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace PhoneNumbers.Test
Expand Down Expand Up @@ -162,10 +163,9 @@ public void TestSharedCost()
[Fact]
public void TestGlobalNetworkNumbers()
{
foreach(var callingCode in phoneNumberUtil.GetSupportedGlobalNetworkCallingCodes())
foreach (var exampleNumber in phoneNumberUtil.GetSupportedGlobalNetworkCallingCodes()
.Select(callingCode => phoneNumberUtil.GetExampleNumberForNonGeoEntity(callingCode)))
{
var exampleNumber =
phoneNumberUtil.GetExampleNumberForNonGeoEntity(callingCode);
Assert.NotNull(exampleNumber);
if (!phoneNumberUtil.IsValidNumber(exampleNumber))
{
Expand Down
52 changes: 6 additions & 46 deletions csharp/PhoneNumbers.Test/TestMetadataFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,7 @@ public void testParseFieldMapFromString_RuntimeExceptionCases()
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString(""));

// Whitespace input.
try
{
MetadataFilter.ParseFieldMapFromString(" ");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString(" "));

// Bad token given as only group.
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("something_else"));
Expand All @@ -413,16 +405,8 @@ public void testParseFieldMapFromString_RuntimeExceptionCases()
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine:something_else"));

// Bad token given as middle group.
try
{
MetadataFilter.ParseFieldMapFromString(
"pager:nationalPrefix:something_else:nationalNumberPattern");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString(
"pager:nationalPrefix:something_else:nationalNumberPattern"));

// Childless field given as parent.
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("nationalPrefix(exampleNumber)"));
Expand Down Expand Up @@ -458,43 +442,19 @@ public void testParseFieldMapFromString_RuntimeExceptionCases()
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("(exampleNumber)"));

// Whitespace parent.
try
{
MetadataFilter.ParseFieldMapFromString(" (exampleNumber)");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString(" (exampleNumber)"));

// Empty child.
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine()"));

// Whitespace child.
try
{
MetadataFilter.ParseFieldMapFromString("fixedLine( )");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine( )"));

// Empty parent and child.
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("()"));

// Whitespace parent and empty child.
try
{
MetadataFilter.ParseFieldMapFromString(" ()");
Assert.True(false);
}
catch (Exception)
{
// Test passed.
}
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString(" ()"));

// Parent field given as a group twice.
Assert.Throws<Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine:uan:fixedLine"));
Expand Down
Loading