React to removal of ToString on TagHelperContent
The code generator generates calls to ToString() on a TagHelperContent when used with dynamic content inside an attribute that needs to be passed to a TagHelper as a string. This change updates the codegen to use GetContent(IHtmlEncoder)
This commit is contained in:
parent
323befaaf1
commit
c9341ee3d7
|
|
@ -650,9 +650,11 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
|
|||
}
|
||||
else
|
||||
{
|
||||
writer.WriteInstanceMethodInvocation(StringValueBufferVariableName,
|
||||
"ToString",
|
||||
endLine: false);
|
||||
writer.WriteInstanceMethodInvocation(
|
||||
StringValueBufferVariableName,
|
||||
_tagHelperContext.TagHelperContentGetContentMethodName,
|
||||
endLine: false,
|
||||
parameters: new string[] { _tagHelperContext.HtmlEncoderPropertyName });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
|
|||
TagHelperContentTypeName = "TagHelperContent";
|
||||
WriteTagHelperAsyncMethodName = "WriteTagHelperAsync";
|
||||
WriteTagHelperToAsyncMethodName = "WriteTagHelperToAsync";
|
||||
TagHelperContentGetContentMethodName = "GetContent";
|
||||
HtmlEncoderPropertyName = "HtmlEncoder";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -161,5 +163,15 @@ namespace Microsoft.AspNet.Razor.CodeGenerators
|
|||
/// <see cref="System.IO.TextWriter"/>.
|
||||
/// </summary>
|
||||
public string WriteTagHelperToAsyncMethodName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the property containing the <c>IHtmlEncoder</c>.
|
||||
/// </summary>
|
||||
public string HtmlEncoderPropertyName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the method used to convert a <c>TagHelperContent</c> into a <see cref="string"/>.
|
||||
/// </summary>
|
||||
public string TagHelperContentGetContentMethodName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ Write(ViewBag.DefaultInterval);
|
|||
#line hidden
|
||||
WriteLiteral(" + 1");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.ToString()));
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.GetContent(HtmlEncoder)));
|
||||
__InputTagHelper.Type = **From custom attribute code renderer**: "text";
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ Write(ViewBag.DefaultInterval);
|
|||
#line hidden
|
||||
WriteLiteral(" + 1");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.ToString()));
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.GetContent(HtmlEncoder)));
|
||||
__InputTagHelper.Type = "text";
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ WriteLiteral(checkbox);
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
#line 16 "ComplexTagHelpers.cshtml"
|
||||
|
|
@ -163,7 +163,7 @@ WriteLiteral(true ? "checkbox" : "anything");
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("tYPe", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
|
|
@ -215,7 +215,7 @@ if(true) {
|
|||
#line hidden
|
||||
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ WriteLiteral(DateTime.Now);
|
|||
#line hidden
|
||||
WriteLiteral(" suffix");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Bound = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Bound = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("bound", __InputTagHelper.Bound);
|
||||
AddHtmlAttributeValues("unbound", __tagHelperExecutionContext, Tuple.Create(Tuple.Create("", 206), Tuple.Create("prefix", 206), true),
|
||||
Tuple.Create(Tuple.Create(" ", 212), Tuple.Create<System.Object, System.Int32>(DateTime.Now, 213), false), Tuple.Create(Tuple.Create(" ", 226), Tuple.Create("suffix", 227), true));
|
||||
|
|
@ -164,7 +164,7 @@ WriteLiteral(int.MaxValue);
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Bound = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Bound = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("bound", __InputTagHelper.Bound);
|
||||
AddHtmlAttributeValues("unbound", __tagHelperExecutionContext,
|
||||
Tuple.Create(Tuple.Create("", 347), Tuple.Create<System.Object, System.Int32>(long.MinValue, 347), false),
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ WriteLiteral(DateTime.Now);
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper.Type = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
#line 6 "EscapedTagHelpers.cshtml"
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ Write(ViewBag.DefaultInterval);
|
|||
#line hidden
|
||||
WriteLiteral(" + 1");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.ToString()));
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-interval", Html.Raw(__tagHelperStringValueBuffer.GetContent(HtmlEncoder)));
|
||||
__InputTagHelper.Type = "text";
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type);
|
||||
__InputTagHelper2.Type = __InputTagHelper.Type;
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ WriteLiteral(literate);
|
|||
#line hidden
|
||||
WriteLiteral("?");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper2.StringDictionaryProperty["cumin"] = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper2.StringDictionaryProperty["cumin"] = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("string-prefix-cumin", __InputTagHelper2.StringDictionaryProperty["cumin"]);
|
||||
__InputTagHelper1.StringDictionaryProperty["cumin"] = __InputTagHelper2.StringDictionaryProperty["cumin"];
|
||||
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ WriteLiteral(literate);
|
|||
#line hidden
|
||||
WriteLiteral("?");
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__InputTagHelper1.StringDictionaryProperty["cumin"] = __tagHelperStringValueBuffer.ToString();
|
||||
__InputTagHelper1.StringDictionaryProperty["cumin"] = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("string-prefix-cumin", __InputTagHelper1.StringDictionaryProperty["cumin"]);
|
||||
__InputTagHelper2.StringDictionaryProperty["cumin"] = __InputTagHelper1.StringDictionaryProperty["cumin"];
|
||||
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ WriteLiteral(DateTime.Now);
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__MyTagHelper.BoundProperty = __tagHelperStringValueBuffer.ToString();
|
||||
__MyTagHelper.BoundProperty = __tagHelperStringValueBuffer.GetContent(HtmlEncoder);
|
||||
__tagHelperExecutionContext.AddTagHelperAttribute("boundproperty", __MyTagHelper.BoundProperty);
|
||||
AddHtmlAttributeValues("unboundproperty", __tagHelperExecutionContext, Tuple.Create(Tuple.Create("", 188), Tuple.Create("Current", 188), true), Tuple.Create(Tuple.Create(" ", 195), Tuple.Create("Time:", 196), true),
|
||||
Tuple.Create(Tuple.Create(" ", 201), Tuple.Create<System.Object, System.Int32>(DateTime.Now, 202), false));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ Write(true);
|
|||
#line default
|
||||
#line hidden
|
||||
__tagHelperStringValueBuffer = EndTagHelperWritingScope();
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-content", Html.Raw(__tagHelperStringValueBuffer.ToString()));
|
||||
__tagHelperExecutionContext.AddHtmlAttribute("data-content", Html.Raw(__tagHelperStringValueBuffer.GetContent(HtmlEncoder)));
|
||||
__tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
|
||||
Instrumentation.BeginContext(35, 85, false);
|
||||
await WriteTagHelperAsync(__tagHelperExecutionContext);
|
||||
|
|
|
|||
Loading…
Reference in New Issue