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 @@ -16,9 +16,10 @@ internal sealed class CreateNewOnMetadataUpdateAttributePass : IntermediateNodeP
{
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
if (FileKinds.IsComponent(codeDocument.GetFileKind()))
if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
documentNode.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{
// Hot reload does not apply to components.
// Not a MVC file. Skip.
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand All @@ -15,6 +15,13 @@ public class ModelExpressionPass : IntermediateNodePassBase, IRazorOptimizationP

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
documentNode.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{
// Not a MVC file. Skip.
return;
}

var visitor = new Visitor();
visitor.Visit(documentNode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
Expand All @@ -15,6 +15,13 @@ public class ViewComponentTagHelperPass : IntermediateNodePassBase, IRazorOptimi

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
documentNode.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{
// Not a MVC file. Skip.
return;
}

var @namespace = documentNode.FindPrimaryNamespace();
var @class = documentNode.FindPrimaryClass();
if (@namespace == null || @class == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ private DocumentIntermediateNode CreateIRDocument(RazorEngine engine, RazorCodeD
}
}

return codeDocument.GetDocumentIntermediateNode();
var irNode = codeDocument.GetDocumentIntermediateNode();
irNode.DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind;

return irNode;
}

private TagHelperIntermediateNode FindTagHelperNode(IntermediateNode node)
Expand Down Expand Up @@ -205,4 +208,4 @@ public override void VisitTagHelper(TagHelperIntermediateNode node)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -36,42 +36,46 @@ public override RazorDiagnosticCollection Diagnostics

public AllowedChildTagDescriptor Build()
{
var validationDiagnostics = Validate();
var diagnostics = new HashSet<RazorDiagnostic>(validationDiagnostics);
var diagnostics = Validate();
if (_diagnostics != null)
{
diagnostics ??= new();
diagnostics.UnionWith(_diagnostics);
}

var displayName = DisplayName ?? Name;
var descriptor = new DefaultAllowedChildTagDescriptor(
Name,
displayName,
diagnostics.ToArray());
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>());

return descriptor;
}

private IEnumerable<RazorDiagnostic> Validate()
private HashSet<RazorDiagnostic> Validate()
{
HashSet<RazorDiagnostic> diagnostics = null;
if (string.IsNullOrWhiteSpace(Name))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRestrictedChildNullOrWhitespace(_parent.GetDisplayName());

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
else if (Name != TagHelperMatchingConventions.ElementCatchAllName)
{
foreach (var character in Name)
{
if (char.IsWhiteSpace(character) || HtmlConventions.InvalidNonWhitespaceHtmlCharacters.Contains(character))
if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRestrictedChild(_parent.GetDisplayName(), Name, character);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
}
}

return diagnostics;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public override void BindAttributeParameter(Action<BoundAttributeParameterDescri

public BoundAttributeDescriptor Build()
{
var validationDiagnostics = Validate();
var diagnostics = new HashSet<RazorDiagnostic>(validationDiagnostics);
var diagnostics = Validate();
if (_diagnostics != null)
{
diagnostics ??= new();
diagnostics.UnionWith(_diagnostics);
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public BoundAttributeDescriptor Build()
CaseSensitive,
parameters,
new Dictionary<string, string>(Metadata),
diagnostics.ToArray())
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>())
{
IsEditorRequired = IsEditorRequired,
};
Expand Down Expand Up @@ -159,13 +159,15 @@ private string GetDisplayName()
return Name;
}

private IEnumerable<RazorDiagnostic> Validate()
private HashSet<RazorDiagnostic> Validate()
{
// data-* attributes are explicitly not implemented by user agents and are not intended for use on
// the server; therefore it's invalid for TagHelpers to bind to them.
const string DataDashPrefix = "data-";
var isDirectiveAttribute = this.IsDirectiveAttribute();

HashSet<RazorDiagnostic> diagnostics = null;

if (string.IsNullOrWhiteSpace(Name))
{
if (IndexerAttributeNamePrefix == null)
Expand All @@ -174,7 +176,8 @@ private IEnumerable<RazorDiagnostic> Validate()
_parent.GetDisplayName(),
GetDisplayName());

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
}
else
Expand All @@ -186,7 +189,8 @@ private IEnumerable<RazorDiagnostic> Validate()
GetDisplayName(),
Name);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}

StringSegment name = Name;
Expand All @@ -201,21 +205,23 @@ private IEnumerable<RazorDiagnostic> Validate()
GetDisplayName(),
Name);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}

for (var i = 0; i < name.Length; i++)
{
var character = name[i];
if (char.IsWhiteSpace(character) || HtmlConventions.InvalidNonWhitespaceHtmlCharacters.Contains(character))
if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeName(
_parent.GetDisplayName(),
GetDisplayName(),
name.Value,
character);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
}
}
Expand All @@ -229,15 +235,17 @@ private IEnumerable<RazorDiagnostic> Validate()
GetDisplayName(),
IndexerAttributeNamePrefix);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
else if (IndexerAttributeNamePrefix.Length > 0 && string.IsNullOrWhiteSpace(IndexerAttributeNamePrefix))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeNullOrWhitespace(
_parent.GetDisplayName(),
GetDisplayName());

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
else
{
Expand All @@ -253,25 +261,29 @@ private IEnumerable<RazorDiagnostic> Validate()
GetDisplayName(),
indexerPrefix.Value);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}

for (var i = 0; i < indexerPrefix.Length; i++)
{
var character = indexerPrefix[i];
if (char.IsWhiteSpace(character) || HtmlConventions.InvalidNonWhitespaceHtmlCharacters.Contains(character))
if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributePrefix(
_parent.GetDisplayName(),
GetDisplayName(),
indexerPrefix.Value,
character);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
}
}
}

return diagnostics;
}

private void EnsureAttributeParameterBuilders()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -51,10 +52,10 @@ public override RazorDiagnosticCollection Diagnostics

public BoundAttributeParameterDescriptor Build()
{
var validationDiagnostics = Validate();
var diagnostics = new HashSet<RazorDiagnostic>(validationDiagnostics);
var diagnostics = Validate();
if (_diagnostics != null)
{
diagnostics ??= new();
diagnostics.UnionWith(_diagnostics);
}
var descriptor = new DefaultBoundAttributeParameterDescriptor(
Expand All @@ -66,7 +67,7 @@ public BoundAttributeParameterDescriptor Build()
GetDisplayName(),
CaseSensitive,
new Dictionary<string, string>(Metadata),
diagnostics.ToArray());
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>());

return descriptor;
}
Expand All @@ -81,28 +82,34 @@ private string GetDisplayName()
return $":{Name}";
}

private IEnumerable<RazorDiagnostic> Validate()
private HashSet<RazorDiagnostic> Validate()
{
HashSet<RazorDiagnostic> diagnostics = null;
if (string.IsNullOrWhiteSpace(Name))
{

var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeParameterNullOrWhitespace(_parent.Name);
yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
else
{
foreach (var character in Name)
{
if (char.IsWhiteSpace(character) || HtmlConventions.InvalidNonWhitespaceHtmlCharacters.Contains(character))
if (char.IsWhiteSpace(character) || HtmlConventions.IsInvalidNonWhitespaceHtmlCharacters(character))
{
var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidBoundAttributeParameterName(
_parent.Name,
Name,
character);

yield return diagnostic;
diagnostics ??= new();
diagnostics.Add(diagnostic);
}
}
}

return diagnostics;
}
}
}
Loading