[Fixes #961] Disable instrumentation for TagHelper attribute values
This commit is contained in:
parent
e549270b4a
commit
7af2f6ff36
|
|
@ -104,6 +104,16 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
|
||||
VisitDefault(node);
|
||||
}
|
||||
|
||||
public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRNode node)
|
||||
{
|
||||
// We don't want to instrument TagHelper attributes. Do nothing.
|
||||
}
|
||||
|
||||
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node)
|
||||
{
|
||||
// We don't want to instrument TagHelper attributes. Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,100 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
n => CSharpExpression("Hi", n));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstrumentationPass_SkipsCSharpExpression_InsideTagHelperAttribute()
|
||||
{
|
||||
// Arrange
|
||||
var builder = RazorIRBuilder.Document();
|
||||
builder.Push(new TagHelperIRNode()
|
||||
{
|
||||
Source = CreateSource(3)
|
||||
});
|
||||
|
||||
builder.Push(new AddTagHelperHtmlAttributeIRNode());
|
||||
|
||||
builder.Push(new CSharpExpressionIRNode()
|
||||
{
|
||||
Source = CreateSource(5)
|
||||
});
|
||||
|
||||
builder.Add(new CSharpTokenIRNode()
|
||||
{
|
||||
Content = "Hi",
|
||||
});
|
||||
|
||||
var irDocument = (DocumentIRNode)builder.Build();
|
||||
|
||||
var pass = new DefaultInstrumentationPass();
|
||||
|
||||
// Act
|
||||
var result = pass.ExecuteCore(TestRazorCodeDocument.CreateEmpty(), irDocument);
|
||||
|
||||
// Assert
|
||||
Children(
|
||||
irDocument,
|
||||
n =>
|
||||
{
|
||||
Assert.IsType<TagHelperIRNode>(n);
|
||||
Children(
|
||||
n,
|
||||
c =>
|
||||
{
|
||||
Assert.IsType<AddTagHelperHtmlAttributeIRNode>(c);
|
||||
Children(
|
||||
c,
|
||||
s => CSharpExpression("Hi", s));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstrumentationPass_SkipsCSharpExpression_InsideTagHelperProperty()
|
||||
{
|
||||
// Arrange
|
||||
var builder = RazorIRBuilder.Document();
|
||||
builder.Push(new TagHelperIRNode()
|
||||
{
|
||||
Source = CreateSource(3)
|
||||
});
|
||||
|
||||
builder.Push(new SetTagHelperPropertyIRNode());
|
||||
|
||||
builder.Push(new CSharpExpressionIRNode()
|
||||
{
|
||||
Source = CreateSource(5)
|
||||
});
|
||||
|
||||
builder.Add(new CSharpTokenIRNode()
|
||||
{
|
||||
Content = "Hi",
|
||||
});
|
||||
|
||||
var irDocument = (DocumentIRNode)builder.Build();
|
||||
|
||||
var pass = new DefaultInstrumentationPass();
|
||||
|
||||
// Act
|
||||
var result = pass.ExecuteCore(TestRazorCodeDocument.CreateEmpty(), irDocument);
|
||||
|
||||
// Assert
|
||||
Children(
|
||||
irDocument,
|
||||
n =>
|
||||
{
|
||||
Assert.IsType<TagHelperIRNode>(n);
|
||||
Children(
|
||||
n,
|
||||
c =>
|
||||
{
|
||||
Assert.IsType<SetTagHelperPropertyIRNode>(c);
|
||||
Children(
|
||||
c,
|
||||
s => CSharpExpression("Hi", s));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstrumentationPass_InstrumentsExecuteTagHelper_InsideTagHelper()
|
||||
{
|
||||
|
|
@ -172,7 +266,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void InstrumentationPass_SkipsExecuteTagHelper_MalformedTagHelper()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
|||
{
|
||||
Name = "value",
|
||||
PropertyName = "FooProp",
|
||||
TypeName = "System.String"
|
||||
TypeName = "System.String" // Gets preallocated
|
||||
},
|
||||
new TagHelperAttributeDescriptor
|
||||
{
|
||||
Name = "date",
|
||||
PropertyName = "BarProp",
|
||||
TypeName = "System.DateTime" // Doesn't get preallocated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,7 +61,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
|||
|
||||
// Assert
|
||||
AssertIRMatchesBaseline(document.GetIRDocument());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
var csharpDocument = document.GetCSharpDocument();
|
||||
AssertCSharpDocumentMatchesBaseline(csharpDocument);
|
||||
Assert.Empty(csharpDocument.Diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma checksum "TestFiles/IntegrationTests/InstrumentationPassIntegrationTest/BasicTest.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7e1ceb3e8ebe2125cd44bea5d9f4ac1acf9ec12b"
|
||||
#pragma checksum "TestFiles/IntegrationTests/InstrumentationPassIntegrationTest/BasicTest.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5898df8049fc1522f646a774050e93cbf5cafb84"
|
||||
namespace
|
||||
{
|
||||
#line hidden
|
||||
|
|
@ -56,8 +56,14 @@ Write("Hello");
|
|||
__tagHelperExecutionContext.Add(__InputTagHelper);
|
||||
__InputTagHelper.FooProp = (string)__tagHelperAttribute_0.Value;
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0);
|
||||
#line 5 "TestFiles/IntegrationTests/InstrumentationPassIntegrationTest/BasicTest.cshtml"
|
||||
__InputTagHelper.BarProp = DateTime.Now;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("date", __InputTagHelper.BarProp, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
|
||||
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1);
|
||||
BeginContext(97, 33, false);
|
||||
BeginContext(97, 52, false);
|
||||
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
||||
{
|
||||
|
|
@ -66,7 +72,7 @@ Write("Hello");
|
|||
Write(__tagHelperExecutionContext.Output);
|
||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||
EndContext();
|
||||
BeginContext(130, 2, true);
|
||||
BeginContext(149, 2, true);
|
||||
WriteLiteral("\r\n");
|
||||
EndContext();
|
||||
}
|
||||
|
|
@ -74,7 +80,7 @@ Write("Hello");
|
|||
__FormTagHelper = CreateTagHelper<global::FormTagHelper>();
|
||||
__tagHelperExecutionContext.Add(__FormTagHelper);
|
||||
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2);
|
||||
BeginContext(71, 68, false);
|
||||
BeginContext(71, 87, false);
|
||||
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
<span someattr>Hola</span>
|
||||
@("Hello")
|
||||
<form unbound="foo">
|
||||
<input value=Hello type='text' />
|
||||
<input value=Hello date=@DateTime.Now type='text' />
|
||||
</form>
|
||||
|
|
@ -19,24 +19,27 @@ Document -
|
|||
CSharpStatement - - BeginContext(69, 2, true);
|
||||
HtmlContent - (69:2,10 [2] BasicTest.cshtml) - \n
|
||||
CSharpStatement - - EndContext();
|
||||
TagHelper - (71:3,0 [68] BasicTest.cshtml)
|
||||
TagHelper - (71:3,0 [87] BasicTest.cshtml)
|
||||
InitializeTagHelperStructure - - form - TagMode.StartTagAndEndTag
|
||||
CSharpStatement - - BeginContext(91, 6, true);
|
||||
HtmlContent - (91:3,20 [6] BasicTest.cshtml) - \n
|
||||
CSharpStatement - - EndContext();
|
||||
TagHelper - (97:4,4 [33] BasicTest.cshtml)
|
||||
TagHelper - (97:4,4 [52] BasicTest.cshtml)
|
||||
InitializeTagHelperStructure - - input - TagMode.SelfClosing
|
||||
CreateTagHelper - - InputTagHelper
|
||||
SetPreallocatedTagHelperProperty - - __tagHelperAttribute_0 - value - FooProp
|
||||
SetTagHelperProperty - (121:4,28 [13] BasicTest.cshtml) - date - BarProp - HtmlAttributeValueStyle.DoubleQuotes
|
||||
CSharpExpression - (122:4,29 [12] BasicTest.cshtml)
|
||||
CSharpToken - (122:4,29 [12] BasicTest.cshtml) - DateTime.Now
|
||||
AddPreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1
|
||||
CSharpStatement - - BeginContext(97, 33, false);
|
||||
CSharpStatement - - BeginContext(97, 52, false);
|
||||
ExecuteTagHelpers -
|
||||
CSharpStatement - - EndContext();
|
||||
CSharpStatement - - BeginContext(130, 2, true);
|
||||
HtmlContent - (130:4,37 [2] BasicTest.cshtml) - \n
|
||||
CSharpStatement - - BeginContext(149, 2, true);
|
||||
HtmlContent - (149:4,56 [2] BasicTest.cshtml) - \n
|
||||
CSharpStatement - - EndContext();
|
||||
CreateTagHelper - - FormTagHelper
|
||||
AddPreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2
|
||||
CSharpStatement - - BeginContext(71, 68, false);
|
||||
CSharpStatement - - BeginContext(71, 87, false);
|
||||
ExecuteTagHelpers -
|
||||
CSharpStatement - - EndContext();
|
||||
|
|
|
|||
Loading…
Reference in New Issue