Add error for using single quotes in add/remove taghelper directive

This commit is contained in:
Ajay Bhargav Baaskaran 2017-09-06 12:28:30 -07:00
parent 00dc95098f
commit aa445ee9b4
2 changed files with 53 additions and 1 deletions

View File

@ -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(

View File

@ -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()
{