Skip to content

Commit

Permalink
Don't allow content in the script and make it self closing, but the o…
Browse files Browse the repository at this point in the history
…utput should always have a start and end tag.
  • Loading branch information
jooni91 committed Feb 16, 2020
1 parent 3800911 commit 0f3fd06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ReCaptcha/TagHelpers/RecaptchaScriptTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace GSoftware.AspNetCore.ReCaptcha.TagHelpers
/// anywhere on your HTML page, but if you use a onload callback function you must place this
/// after that callback to avoid race conditions.
/// </summary>
[HtmlTargetElement("recaptcha-script", TagStructure = TagStructure.WithoutEndTag)]
public class RecaptchaScriptTagHelper : TagHelper
{
private const string RecaptchaScriptEndpoint = "https://www.google.com/recaptcha/api.js";
Expand Down Expand Up @@ -48,6 +49,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
_ = output ?? throw new ArgumentNullException(nameof(output));

output.TagName = "script";
output.TagMode = TagMode.StartTagAndEndTag;

if (Render == Render.V3)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/ReCaptcha.Tests/TagHelpers/RecaptchaScriptTagHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public void Process_ShouldChangeTagTo_ScriptTag()
Assert.AreEqual("script", _tagHelperOutput.TagName);
}

[Test]
public void Process_ShouldChange_TagModeTo_StartTagAndEndTag()
{
// Arrange
var scriptTagHelper = new RecaptchaScriptTagHelper(_settingsMock.Object);
_tagHelperOutput.TagMode = TagMode.SelfClosing;

// Act
scriptTagHelper.Process(_context, _tagHelperOutput);

// Assert
Assert.AreEqual(TagMode.StartTagAndEndTag, _tagHelperOutput.TagMode);
}

[Test]
public void Process_ShouldContain_ThreeAttributes()
{
Expand Down

0 comments on commit 0f3fd06

Please sign in to comment.