Fix crash with code blocks in tag helper attributes (dotnet/aspnetcore-tooling#190)
* Fix crash with code blocks in tag helper attributes
* Better fix
* Fixed another case
\n\nCommit migrated from 9e97ba9b97
This commit is contained in:
parent
83c8c0cba2
commit
b15af76917
|
|
@ -480,6 +480,28 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
return base.VisitRazorMetaCode(node);
|
||||
}
|
||||
|
||||
public override SyntaxNode VisitCSharpStatement(CSharpStatementSyntax node)
|
||||
{
|
||||
// We don't support code blocks inside tag helper attributes. Don't rewrite anything inside a code block.
|
||||
// E.g, <p age="@{1 + 2}"> is not supported.
|
||||
return node;
|
||||
}
|
||||
|
||||
public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
|
||||
{
|
||||
// We don't support directives inside tag helper attributes. Don't rewrite anything inside a directive.
|
||||
// E.g, <p age="@functions { }"> is not supported.
|
||||
return node;
|
||||
}
|
||||
|
||||
public override SyntaxNode VisitMarkupElement(MarkupElementSyntax node)
|
||||
{
|
||||
// We're visiting an attribute value. If we encounter a MarkupElement this means the attribute value is invalid.
|
||||
// We don't want to rewrite anything here.
|
||||
// E.g, <my age="@if (true) { <my4 age=... }"></my4>
|
||||
return node;
|
||||
}
|
||||
|
||||
public override SyntaxNode VisitCSharpExpressionLiteral(CSharpExpressionLiteralSyntax node)
|
||||
{
|
||||
if (!_tryParseResult.IsBoundNonStringAttribute)
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
baselineDiagnostics = diagnosticsFile.ReadAllText();
|
||||
}
|
||||
|
||||
var actualDiagnostics = string.Concat(cSharpDocument.Diagnostics.Select(d => RazorDiagnosticSerializer.Serialize(d) + "\r\n"));
|
||||
var actualDiagnostics = string.Concat(cSharpDocument.Diagnostics.Select(d => NormalizeNewLines(RazorDiagnosticSerializer.Serialize(d)) + "\r\n"));
|
||||
Assert.Equal(baselineDiagnostics, actualDiagnostics);
|
||||
}
|
||||
|
||||
|
|
@ -541,6 +541,30 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
|
|||
}
|
||||
return base.VisitCSharpExpressionLiteral(node);
|
||||
}
|
||||
|
||||
public override Syntax.SyntaxNode VisitCSharpStatement(CSharpStatementSyntax node)
|
||||
{
|
||||
if (node.FirstAncestorOrSelf<MarkupTagHelperAttributeValueSyntax>() != null)
|
||||
{
|
||||
// We don't support code blocks inside tag helper attribute values.
|
||||
// If it exists, we don't want to track its code spans for source mappings.
|
||||
return node;
|
||||
}
|
||||
|
||||
return base.VisitCSharpStatement(node);
|
||||
}
|
||||
|
||||
public override Syntax.SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node)
|
||||
{
|
||||
if (node.FirstAncestorOrSelf<MarkupTagHelperAttributeValueSyntax>() != null)
|
||||
{
|
||||
// We don't support Razor directives inside tag helper attribute values.
|
||||
// If it exists, we don't want to track its code spans for source mappings.
|
||||
return node;
|
||||
}
|
||||
|
||||
return base.VisitRazorDirective(node);
|
||||
}
|
||||
}
|
||||
|
||||
private static string EscapeWhitespace(string content)
|
||||
|
|
|
|||
Loading…
Reference in New Issue