Skip to content

Escape page titles once when they are built - #3228

Draft
theseanything wants to merge 1 commit into
mainfrom
escape-page-title
Draft

theseanything wants to merge 1 commit into
mainfrom
escape-page-title

Conversation

@theseanything

@theseanything theseanything commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this pull request solve?

set_page_title marked every title as html_safe, including titles built from form, group, page and user names. The <title> only ended up escaped because Array#join in page_title returns a plain String, so ERB escaped it on output. Anything reading content_for(:title) directly would get unescaped markup.

This change lets content_for escape the title when it's stored, and uses safe_join in page_title so the title is escaped exactly once. That keeps the fix from #125 for double-escaped characters such as apostrophes.

set_page_title marked every title as html_safe, including form, group
and user names that people type in. The rendered <title> only came out
escaped because Array#join in page_title returns a plain String, which
drops the html_safe flag before ERB outputs it. Anything reading
content_for(:title) directly would get the raw markup.

Let content_for escape the title when it is stored, and use safe_join
in page_title so the result is not escaped a second time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-3228.admin.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant