[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);
|
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));
|
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]
|
[Fact]
|
||||||
public void InstrumentationPass_InstrumentsExecuteTagHelper_InsideTagHelper()
|
public void InstrumentationPass_InstrumentsExecuteTagHelper_InsideTagHelper()
|
||||||
{
|
{
|
||||||
|
|
@ -172,7 +266,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InstrumentationPass_SkipsExecuteTagHelper_MalformedTagHelper()
|
public void InstrumentationPass_SkipsExecuteTagHelper_MalformedTagHelper()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
{
|
{
|
||||||
Name = "value",
|
Name = "value",
|
||||||
PropertyName = "FooProp",
|
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
|
// Assert
|
||||||
AssertIRMatchesBaseline(document.GetIRDocument());
|
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
|
namespace
|
||||||
{
|
{
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
@ -56,8 +56,14 @@ Write("Hello");
|
||||||
__tagHelperExecutionContext.Add(__InputTagHelper);
|
__tagHelperExecutionContext.Add(__InputTagHelper);
|
||||||
__InputTagHelper.FooProp = (string)__tagHelperAttribute_0.Value;
|
__InputTagHelper.FooProp = (string)__tagHelperAttribute_0.Value;
|
||||||
__tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0);
|
__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);
|
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1);
|
||||||
BeginContext(97, 33, false);
|
BeginContext(97, 52, false);
|
||||||
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||||
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
||||||
{
|
{
|
||||||
|
|
@ -66,7 +72,7 @@ Write("Hello");
|
||||||
Write(__tagHelperExecutionContext.Output);
|
Write(__tagHelperExecutionContext.Output);
|
||||||
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
__tagHelperExecutionContext = __tagHelperScopeManager.End();
|
||||||
EndContext();
|
EndContext();
|
||||||
BeginContext(130, 2, true);
|
BeginContext(149, 2, true);
|
||||||
WriteLiteral("\r\n");
|
WriteLiteral("\r\n");
|
||||||
EndContext();
|
EndContext();
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +80,7 @@ Write("Hello");
|
||||||
__FormTagHelper = CreateTagHelper<global::FormTagHelper>();
|
__FormTagHelper = CreateTagHelper<global::FormTagHelper>();
|
||||||
__tagHelperExecutionContext.Add(__FormTagHelper);
|
__tagHelperExecutionContext.Add(__FormTagHelper);
|
||||||
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2);
|
__tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2);
|
||||||
BeginContext(71, 68, false);
|
BeginContext(71, 87, false);
|
||||||
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||||
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
if (!__tagHelperExecutionContext.Output.IsContentModified)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
<span someattr>Hola</span>
|
<span someattr>Hola</span>
|
||||||
@("Hello")
|
@("Hello")
|
||||||
<form unbound="foo">
|
<form unbound="foo">
|
||||||
<input value=Hello type='text' />
|
<input value=Hello date=@DateTime.Now type='text' />
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -19,24 +19,27 @@ Document -
|
||||||
CSharpStatement - - BeginContext(69, 2, true);
|
CSharpStatement - - BeginContext(69, 2, true);
|
||||||
HtmlContent - (69:2,10 [2] BasicTest.cshtml) - \n
|
HtmlContent - (69:2,10 [2] BasicTest.cshtml) - \n
|
||||||
CSharpStatement - - EndContext();
|
CSharpStatement - - EndContext();
|
||||||
TagHelper - (71:3,0 [68] BasicTest.cshtml)
|
TagHelper - (71:3,0 [87] BasicTest.cshtml)
|
||||||
InitializeTagHelperStructure - - form - TagMode.StartTagAndEndTag
|
InitializeTagHelperStructure - - form - TagMode.StartTagAndEndTag
|
||||||
CSharpStatement - - BeginContext(91, 6, true);
|
CSharpStatement - - BeginContext(91, 6, true);
|
||||||
HtmlContent - (91:3,20 [6] BasicTest.cshtml) - \n
|
HtmlContent - (91:3,20 [6] BasicTest.cshtml) - \n
|
||||||
CSharpStatement - - EndContext();
|
CSharpStatement - - EndContext();
|
||||||
TagHelper - (97:4,4 [33] BasicTest.cshtml)
|
TagHelper - (97:4,4 [52] BasicTest.cshtml)
|
||||||
InitializeTagHelperStructure - - input - TagMode.SelfClosing
|
InitializeTagHelperStructure - - input - TagMode.SelfClosing
|
||||||
CreateTagHelper - - InputTagHelper
|
CreateTagHelper - - InputTagHelper
|
||||||
SetPreallocatedTagHelperProperty - - __tagHelperAttribute_0 - value - FooProp
|
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
|
AddPreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1
|
||||||
CSharpStatement - - BeginContext(97, 33, false);
|
CSharpStatement - - BeginContext(97, 52, false);
|
||||||
ExecuteTagHelpers -
|
ExecuteTagHelpers -
|
||||||
CSharpStatement - - EndContext();
|
CSharpStatement - - EndContext();
|
||||||
CSharpStatement - - BeginContext(130, 2, true);
|
CSharpStatement - - BeginContext(149, 2, true);
|
||||||
HtmlContent - (130:4,37 [2] BasicTest.cshtml) - \n
|
HtmlContent - (149:4,56 [2] BasicTest.cshtml) - \n
|
||||||
CSharpStatement - - EndContext();
|
CSharpStatement - - EndContext();
|
||||||
CreateTagHelper - - FormTagHelper
|
CreateTagHelper - - FormTagHelper
|
||||||
AddPreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2
|
AddPreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2
|
||||||
CSharpStatement - - BeginContext(71, 68, false);
|
CSharpStatement - - BeginContext(71, 87, false);
|
||||||
ExecuteTagHelpers -
|
ExecuteTagHelpers -
|
||||||
CSharpStatement - - EndContext();
|
CSharpStatement - - EndContext();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue