diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/CSharpIdentifier.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/CSharpIdentifier.cs index 4e34345903..a7571910d7 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/CSharpIdentifier.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/CSharpIdentifier.cs @@ -53,6 +53,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X public static string SanitizeClassName(string inputName) { + if (string.IsNullOrEmpty(inputName)) + { + return inputName; + } + if (!IsIdentifierStart(inputName[0]) && IsIdentifierPart(inputName[0])) { inputName = "_" + inputName; diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/CSharpIdentifier.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/CSharpIdentifier.cs index 77a5e8f54e..28e08063e6 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/CSharpIdentifier.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/src/CSharpIdentifier.cs @@ -53,6 +53,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X public static string SanitizeClassName(string inputName) { + if (string.IsNullOrEmpty(inputName)) + { + return inputName; + } + if (!IsIdentifierStart(inputName[0]) && IsIdentifierPart(inputName[0])) { inputName = "_" + inputName; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/CSharpIdentifier.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/CSharpIdentifier.cs index 1ec6188aed..b5904e6f1d 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/CSharpIdentifier.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/CSharpIdentifier.cs @@ -35,6 +35,11 @@ namespace Microsoft.AspNetCore.Razor.Language public static string SanitizeIdentifier(string inputName) { + if (string.IsNullOrEmpty(inputName)) + { + return inputName; + } + if (!IsIdentifierStart(inputName[0]) && IsIdentifierPart(inputName[0])) { inputName = "_" + inputName; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentGenericTypePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentGenericTypePass.cs index 62ee1a8980..ee92d484a6 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentGenericTypePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentGenericTypePass.cs @@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components // Method name is generated and guaranteed not to collide, since it's unique for each // component call site. - MethodName = $"Create{node.TagName}_{_id++}", + MethodName = $"Create{CSharpIdentifier.SanitizeIdentifier(node.TagName)}_{_id++}", FullTypeName = @namespace + ".TypeInference", };