Skip to content

Commit bdcddc4

Browse files
allow hyphens in function name
1 parent 2a78664 commit bdcddc4

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

dotnet/src/InternalUtilities/src/Diagnostics/KernelVerify.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ internal static partial class KernelVerify
1313
{
1414
#if NET
1515
[GeneratedRegex("^[0-9A-Za-z_]*$")]
16-
private static partial Regex AsciiLettersDigitsUnderscoresRegex();
16+
private static partial Regex AllowedPluginNameSymbolsRegex();
17+
18+
[GeneratedRegex("^[0-9A-Za-z_-]*$")]
19+
private static partial Regex AllowedFunctionNameSymbolsRegex();
1720
#else
18-
private static Regex AsciiLettersDigitsUnderscoresRegex() => s_asciiLettersDigitsUnderscoresRegex;
19-
private static readonly Regex s_asciiLettersDigitsUnderscoresRegex = new("^[0-9A-Za-z_]*$", RegexOptions.Compiled);
21+
private static Regex AllowedPluginNameSymbolsRegex() => s_allowedPluginNameSymbolsRegex;
22+
private static readonly Regex s_allowedPluginNameSymbolsRegex = new("^[0-9A-Za-z_]*$", RegexOptions.Compiled);
23+
24+
private static Regex AllowedFunctionNameSymbolsRegex() => s_allowedFunctionNameSymbolsRegex;
25+
private static readonly Regex s_allowedFunctionNameSymbolsRegex = new("^[0-9A-Za-z_-]*$", RegexOptions.Compiled);
2026
#endif
2127

2228
internal static void ValidPluginName([NotNull] string? pluginName, IReadOnlyKernelPluginCollection? plugins = null, [CallerArgumentExpression(nameof(pluginName))] string? paramName = null)
2329
{
2430
Verify.NotNullOrWhiteSpace(pluginName);
25-
if (!AsciiLettersDigitsUnderscoresRegex().IsMatch(pluginName))
31+
if (!AllowedPluginNameSymbolsRegex().IsMatch(pluginName))
2632
{
2733
Verify.ThrowArgumentInvalidName("plugin name", pluginName, paramName);
2834
}
@@ -36,7 +42,7 @@ internal static void ValidPluginName([NotNull] string? pluginName, IReadOnlyKern
3642
internal static void ValidFunctionName([NotNull] string? functionName, [CallerArgumentExpression(nameof(functionName))] string? paramName = null)
3743
{
3844
Verify.NotNullOrWhiteSpace(functionName);
39-
if (!AsciiLettersDigitsUnderscoresRegex().IsMatch(functionName))
45+
if (!AllowedFunctionNameSymbolsRegex().IsMatch(functionName))
4046
{
4147
Verify.ThrowArgumentInvalidName("function name", functionName, paramName);
4248
}

dotnet/src/InternalUtilities/src/Diagnostics/Verify.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ namespace Microsoft.SemanticKernel;
1515
internal static partial class Verify
1616
{
1717
#if NET
18-
[GeneratedRegex("^[0-9A-Za-z_]*$")]
19-
private static partial Regex AsciiLettersDigitsUnderscoresRegex();
20-
2118
[GeneratedRegex("^[^.]+\\.[^.]+$")]
2219
private static partial Regex FilenameRegex();
2320
#else
24-
private static Regex AsciiLettersDigitsUnderscoresRegex() => s_asciiLettersDigitsUnderscoresRegex;
25-
private static readonly Regex s_asciiLettersDigitsUnderscoresRegex = new("^[0-9A-Za-z_]*$", RegexOptions.Compiled);
26-
2721
private static Regex FilenameRegex() => s_filenameRegex;
2822
private static readonly Regex s_filenameRegex = new("^[^.]+\\.[^.]+$", RegexOptions.Compiled);
2923
#endif
@@ -75,15 +69,6 @@ public static void True(bool condition, string message, [CallerArgumentExpressio
7569
}
7670
}
7771

78-
internal static void ValidFunctionName([NotNull] string? functionName, [CallerArgumentExpression(nameof(functionName))] string? paramName = null)
79-
{
80-
NotNullOrWhiteSpace(functionName);
81-
if (!AsciiLettersDigitsUnderscoresRegex().IsMatch(functionName))
82-
{
83-
ThrowArgumentInvalidName("function name", functionName, paramName);
84-
}
85-
}
86-
8772
internal static void ValidFilename([NotNull] string? filename, [CallerArgumentExpression(nameof(filename))] string? paramName = null)
8873
{
8974
NotNullOrWhiteSpace(filename);

0 commit comments

Comments
 (0)