Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes values are encoded even if passed with the safe filter #4940

Open
querkmachine opened this issue Apr 19, 2024 · 0 comments
Open
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) nunjucks

Comments

@querkmachine
Copy link
Member

Description of the issue

Currently it is not possible to pass unescaped HTML as an attribute value when passing attributes as an object. This is because the govukAttributes macro indiscriminately escapes all values, even those that have previously been passed through the safe filter.

This is likely an edge case situation, but it may be considered an unexpected outcome, as it directly contradicts the expectations set by using the safe filter.

Spun off from #4937.

Steps to reproduce the issue

Pass HTML as a value into a component's attributes parameter.

{{ govukBackLink({
  attributes: {
    'data-safe-html': '<i>Test&ing</i>' | safe
  }
}) }}

Actual vs expected behaviour

Actual

HTML is indiscriminately escaped, despite using the safe filter indicating it shouldn't be escaped.

<a 
  href="#"
  class="govuk-back-link"
  data-safe-html="&lt;i&gt;Test&amp;ing&lt;/i&gt;">
  Back
</a>

Expected

HTML is not escaped due to use of safe filter.

<a 
  href="#"
  class="govuk-back-link"
  data-safe-html="<i>Test&ing</i>">
  Back
</a>

Additional information

This does not happen if the attributes are passed as a string instead. This can be used as a workaround in the meantime.

{{ govukBackLink({
  attributes: ' data-safe-html="<i>Test&ing</i>"'
}) }}
<a
  href="#"
  class="govuk-back-link"
  data-safe-html="<i>Test&ing</i>">
  Back
</a>

Environment

  • GOV.UK Frontend Version: 5.2.0, 5.3.0
@querkmachine querkmachine added 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) nunjucks labels Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) nunjucks
Projects
None yet
Development

No branches or pull requests

1 participant