Skip to content

Commit 6cdf2ed

Browse files
committed
Fix attribute encoding for new component generation
1 parent c7ef6a1 commit 6cdf2ed

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- dev
77
- main
8+
- v*
89
tags:
910
- v*
1011
paths-ignore:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.2.1
4+
5+
### Fixes
6+
7+
#### Attribute encoding
8+
Newly-refactored tag helpers now correctly encode their attributes.
9+
310
## 2.2.0
411

512
Targets GOV.UK Frontend v5.2.0.

src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ await output.GetChildContentAsync() :
9898

9999
if (validationMessage != null)
100100
{
101-
resolvedContent = new HtmlString(HtmlEncoder.Default.Encode(validationMessage));
101+
resolvedContent = validationMessage.EncodeHtml();
102102
}
103103
}
104104

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Text.Encodings.Web;
3+
using Microsoft.AspNetCore.Html;
4+
5+
namespace GovUk.Frontend.AspNetCore.TagHelpers;
6+
7+
internal static class Extensions
8+
{
9+
[return: NotNullIfNotNull(nameof(value))]
10+
public static IHtmlContent? EncodeHtml(this string? value) =>
11+
value is not null ? new HtmlString(HtmlEncoder.Default.Encode(value)) : null;
12+
}

0 commit comments

Comments
 (0)