Add error for using single quotes in add/remove taghelper directive
This commit is contained in:
parent
00dc95098f
commit
aa445ee9b4
|
|
@ -2032,7 +2032,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
// Ensure that we have valid lookupStrings to work with. The valid format is "typeName, assemblyName"
|
||||
if (lookupStrings == null ||
|
||||
lookupStrings.Any(string.IsNullOrWhiteSpace) ||
|
||||
lookupStrings.Length != 2)
|
||||
lookupStrings.Length != 2 ||
|
||||
text.StartsWith("'") ||
|
||||
text.EndsWith("'"))
|
||||
{
|
||||
errors.Add(
|
||||
RazorDiagnostic.Create(
|
||||
|
|
|
|||
|
|
@ -1203,6 +1203,31 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
legacyErrors: expectedErrors)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveTagHelperDirective_SingleQuotes_AddsError()
|
||||
{
|
||||
var expectedErrors = new[]
|
||||
{
|
||||
new RazorError(
|
||||
Resources.FormatInvalidTagHelperLookupText("'*, Foo'"),
|
||||
new SourceLocation(17, 0, 17),
|
||||
length: 8)
|
||||
};
|
||||
|
||||
ParseBlockTest("@removeTagHelper '*, Foo'",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.RemoveTagHelperKeyword)
|
||||
.Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false)
|
||||
.Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Code("'*, Foo'")
|
||||
.AsRemoveTagHelper(
|
||||
"'*, Foo'",
|
||||
"'*, Foo'",
|
||||
legacyErrors: expectedErrors)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveTagHelperDirective_WithQuotes_InvalidLookupText_AddsError()
|
||||
{
|
||||
|
|
@ -1421,6 +1446,31 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
legacyErrors: expectedErrors)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddTagHelperDirective_SingleQuotes_AddsError()
|
||||
{
|
||||
var expectedErrors = new[]
|
||||
{
|
||||
new RazorError(
|
||||
Resources.FormatInvalidTagHelperLookupText("'*, Foo'"),
|
||||
new SourceLocation(14, 0, 14),
|
||||
length: 8)
|
||||
};
|
||||
|
||||
ParseBlockTest("@addTagHelper '*, Foo'",
|
||||
new DirectiveBlock(
|
||||
Factory.CodeTransition(),
|
||||
Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword)
|
||||
.Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Markup, " ", markup: false)
|
||||
.Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Code("'*, Foo'")
|
||||
.AsAddTagHelper(
|
||||
"'*, Foo'",
|
||||
"'*, Foo'",
|
||||
legacyErrors: expectedErrors)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddTagHelperDirective_SupportsSpaces()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue