Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,19 @@ private static bool InAttributeContainingCSharp(

if (markupAttributeValue is not null)
{
if (!processedAttributes.TryGetValue(markupAttributeValue.Span, out var doesAttributeContainNonMarkup))
if (!processedAttributes.TryGetValue(markupAttributeValue.Span, out var shouldFilterDiagnostic))
{
doesAttributeContainNonMarkup = CheckIfAttributeContainsNonMarkupNodes(markupAttributeValue);
processedAttributes.Add(markupAttributeValue.Span, doesAttributeContainNonMarkup);
// If a component attribute is spread across multiple lines, it's not valid Html so the Html server can't be expected to reason
// about the contents correctly
shouldFilterDiagnostic = markupAttributeValue is MarkupTagHelperAttributeValueSyntax &&
markupAttributeValue.GetLinePositionSpan(syntaxTree.Source).SpansMultipleLines();

// Similarly, if the attribute value contains non-markup, the Html could report false positives
shouldFilterDiagnostic |= CheckIfAttributeContainsNonMarkupNodes(markupAttributeValue);
processedAttributes.Add(markupAttributeValue.Span, shouldFilterDiagnostic);
}

return doesAttributeContainNonMarkup;
return shouldFilterDiagnostic;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,58 @@ public Task FilterPropertyNameInCss()
}]);
}

[Fact]
public Task FilterFromMultilineComponentAttributes()
{
var firstLine = "Hello this is a";
TestCode input = $$"""
<File1 Title="{{firstLine}}
multiline attribute" />

@code
{
[Parameter]
public string Title { get; set; }
}
""";

return VerifyDiagnosticsAsync(input,
htmlResponse: [new VSInternalDiagnosticReport
{
Diagnostics =
[
new LspDiagnostic
{
Code = HtmlErrorCodes.MismatchedAttributeQuotesErrorCode,
Range = SourceText.From(input.Text).GetRange(new TextSpan(input.Text.IndexOf(firstLine), firstLine.Length))
},
]
}]);
}

[Fact]
public Task DontFilterFromMultilineHtmlAttributes()
{
var firstLine = "Hello this is a";
TestCode input = $$"""
<div class="{|HTML0005:{{firstLine}}|}
multiline attribute" />
""";

return VerifyDiagnosticsAsync(input,
htmlResponse: [new VSInternalDiagnosticReport
{
Diagnostics =
[
new LspDiagnostic
{
Code = HtmlErrorCodes.MismatchedAttributeQuotesErrorCode,
Range = SourceText.From(input.Text).GetRange(new TextSpan(input.Text.IndexOf(firstLine), firstLine.Length))
},
]
}]);
}

[Theory]
[InlineData("", "\"")]
[InlineData("", "'")]
Expand Down