Skip to content

Commit 4cbc916

Browse files
authored
fix: Don't encode characters. (Fixes #898) (#899)
1 parent 26a7fc1 commit 4cbc916

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
### Fixed
10+
- The created HTML contained encoded strings. Reported by [@tobiasbrandstaedter](https://github.com/tobiasbrandstaedter). Fixed by [@linkdotnet](https://github.com/linkdotnet).
11+
912
## [1.11.7] - 2022-10-13
1013

1114
### Added

src/bunit.web/Rendering/Internal/Htmlizer.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ internal static class Htmlizer
2121
internal const string BlazorAttrPrefix = "blazor:";
2222
internal const string ElementReferenceAttrName = BlazorAttrPrefix + "elementReference";
2323

24-
private static readonly HtmlEncoder HtmlEncoder = HtmlEncoder.Default;
25-
2624
private static readonly HashSet<string> SelfClosingElements = new(StringComparer.OrdinalIgnoreCase)
2725
{
2826
"area",
@@ -95,7 +93,7 @@ private static int RenderCore(
9593
case RenderTreeFrameType.Attribute:
9694
throw new InvalidOperationException($"Attributes should only be encountered within {nameof(RenderElement)}");
9795
case RenderTreeFrameType.Text:
98-
context.Result.Append(HtmlEncoder.Encode(frame.TextContent));
96+
context.Result.Append(frame.TextContent);
9997
return position + 1;
10098
case RenderTreeFrameType.Markup:
10199
context.Result.Append(frame.MarkupContent);
@@ -272,7 +270,7 @@ private static int RenderAttributes(
272270
result.Append(frame.AttributeName);
273271
result.Append('=');
274272
result.Append('"');
275-
result.Append(HtmlEncoder.Encode(value));
273+
result.Append(value);
276274
result.Append('"');
277275
break;
278276
default:
@@ -299,4 +297,4 @@ public ReadOnlySpan<RenderTreeFrame> GetRenderTreeFrames(int componentId)
299297

300298
public string? ClosestSelectValueAsString { get; set; }
301299
}
302-
}
300+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p style="@Escaped">@Escaped</p>
2+
3+
@code {
4+
private string Escaped => "url('')";
5+
}

tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,12 @@ public async Task CanHandleRemovedParentObjectsAsync()
609609
cut.WaitForState(() => !cut.FindAll("div").Any());
610610
cut.FindAll("div").Count.ShouldBe(0);
611611
}
612-
}
612+
613+
[Fact]
614+
public void EscapableCharactersDontGetEncoded()
615+
{
616+
var cut = RenderComponent<ComponentWithEscapableCharacters>();
617+
618+
cut.Markup.ShouldBe("<p style=\"url('')\">url('')</p>");
619+
}
620+
}

0 commit comments

Comments
 (0)