Skip to content

Commit 27a43f7

Browse files
committed
fix: Htmlizer can handle NamedEvents
Fixes #1438
1 parent f8ede16 commit 27a43f7

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

CHANGELOG.md

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

1111
- bUnit's built-in HTML parser did not correctly parse full HTML documents that included a <!DOCTYPE html> as the first element. Fixed by [@egil](https://github.com/egil).
12+
- `@formname` directive led to an `InvalidOperationException` when used on a form element. Reported by [@suzu2469](https://github.com/suzu2469) in [#1438](https://github.com/bUnit-dev/bUnit/issues/1438).
13+
Fixed by [@egil](https://github.com/egil)/[@linkdotnet](https://github.com/linkdotnet).
1214

1315
### Changed
1416
- `NavigationManager` is again registered as a singleton instead of scoped.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ int position
119119
case RenderTreeFrameType.ElementReferenceCapture:
120120
case RenderTreeFrameType.ComponentReferenceCapture:
121121
return position + 1;
122+
#if NET8_0_OR_GREATER
123+
case RenderTreeFrameType.NamedEvent:
124+
return position + 1;
125+
#endif
122126
default:
123127
throw new InvalidOperationException(
124128
$"Invalid element frame type '{frame.FrameType}'."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<form method="post" @formname="sample-form">
2+
<button type="submit">Submit</button>
3+
</form>

tests/bunit.web.tests/Rendering/Internal/HtmlizerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,21 @@ public void Test003()
3939

4040
cut.Find("button").HasAttribute("blazor:elementreference").ShouldBeTrue();
4141
}
42+
43+
#if NET8_0_OR_GREATER
44+
[Fact(DisplayName = "Htmlizer ignores NamedEvents")]
45+
public void Test004()
46+
{
47+
var cut = RenderComponent<FormNameComponent>();
4248

49+
cut.MarkupMatches("""
50+
<form method="post">
51+
<button type="submit">Submit</button>
52+
</form>
53+
""");
54+
}
55+
#endif
56+
4357
private sealed class Htmlizer01Component : ComponentBase
4458
{
4559
public ElementReference ButtomElmRef { get; set; }

0 commit comments

Comments
 (0)