Skip to content

Commit 8eb8c26

Browse files
committed
Ensuring function name comparison is done consistently
1 parent ab9c7d5 commit 8eb8c26

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

src/WebJobs.Script.WebHost/Diagnostics/FunctionInstanceLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private FunctionMetadata GetFunctionMetadata(string functionName)
126126
{
127127
FunctionMetadata GetMetadataFromCollection(IEnumerable<FunctionMetadata> functions)
128128
{
129-
return functions.FirstOrDefault(p => string.Equals(p.Name, functionName, StringComparison.OrdinalIgnoreCase));
129+
return functions.FirstOrDefault(p => Utility.FunctionNamesMatch(p.Name, functionName));
130130
}
131131

132132
return GetMetadataFromCollection(_metadataManager.Functions)

src/WebJobs.Script.WebHost/Management/WebFunctionsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ await functionMetadata
165165
{
166166
var hostOptions = _applicationHostOptions.CurrentValue.ToHostOptions();
167167
var functionMetadata = _functionMetadataProvider.GetFunctionMetadata(true)
168-
.FirstOrDefault(metadata => metadata.Name == name);
168+
.FirstOrDefault(metadata => Utility.FunctionNamesMatch(metadata.Name, name));
169169

170170
if (functionMetadata != null)
171171
{

src/WebJobs.Script/Host/FunctionMetadataManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private ImmutableArray<FunctionMetadata> LoadFunctionMetadata()
4747
if (functionsWhiteList != null)
4848
{
4949
_logger.LogInformation($"A function whitelist has been specified, excluding all but the following functions: [{string.Join(", ", functionsWhiteList)}]");
50-
metadata = metadata.Where(function => functionsWhiteList.Any(functionName => functionName.Equals(function.Name, StringComparison.CurrentCultureIgnoreCase))).ToImmutableArray();
50+
metadata = metadata.Where(function => functionsWhiteList.Any(functionName => Utility.FunctionNamesMatch(function.Name, functionName))).ToImmutableArray();
5151
Errors = _functionMetadataProvider.FunctionErrors.Where(kvp => functionsWhiteList.Any(functionName => functionName.Equals(kvp.Key, StringComparison.CurrentCultureIgnoreCase))).ToImmutableDictionary<string, ImmutableArray<string>>();
5252
}
5353
_logger.FunctionMetadataManagerFunctionsLoaded(metadata.Length);

src/WebJobs.Script/Utility.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ public static bool IsValidFunctionName(string functionName)
172172
return FunctionNameValidationRegex.IsMatch(functionName);
173173
}
174174

175+
public static bool FunctionNamesMatch(string functionName, string comparand)
176+
{
177+
return string.Equals(functionName, comparand, StringComparison.OrdinalIgnoreCase);
178+
}
179+
175180
// "Namespace.Class.Method" --> "Namespace.Class"
176181
public static string GetFullClassName(string fullFunctionName)
177182
{

test/WebJobs.Script.Tests/UtilityTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ public async Task DelayWithBackoffAsync_DelaysAsExpected()
9999
Assert.True(roundedElapsedSpan >= TimeSpan.FromSeconds(2), $"Expected roundedElapsedSpan >= TimeSpan.FromSeconds(2); Actual: {roundedElapsedSpan.TotalSeconds}");
100100
}
101101

102+
[Theory]
103+
[InlineData("Function1", "Function1", "en-US", true)]
104+
[InlineData("function1", "Function1", "en-US", true)]
105+
[InlineData("Função", "FunçÃo", "pt-BR", true)]
106+
[InlineData("HttptRIGGER", "Httptrigger", "ja-JP", true)]
107+
[InlineData("Iasdf1", "iasdf1", "tr-TR", true)]
108+
public void FunctionNamesMatch_ReturnsExpectedResult(string functionNameA, string functionNameB, string cultureInfo, bool expectMatch)
109+
{
110+
CultureInfo environmentCulture = Thread.CurrentThread.CurrentCulture;
111+
112+
try
113+
{
114+
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureInfo);
115+
Assert.Equal(expectMatch, Utility.FunctionNamesMatch(functionNameA, functionNameB));
116+
}
117+
finally
118+
{
119+
Thread.CurrentThread.CurrentCulture = environmentCulture;
120+
}
121+
}
122+
102123
[Theory]
103124
[InlineData(1, null, null, null, "00:00:00")]
104125
[InlineData(2, null, null, null, "00:00:02")]

0 commit comments

Comments
 (0)