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

Fix <title> tag double HTML escaping #1626

Merged
merged 1 commit into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ html lang="#{I18n.locale}" class='no-js'
meta http-equiv="refresh" content="#{yield(:meta_refresh)}"

title
= content_for?(:title) ? APP_NAME + ' - ' + yield(:title) : APP_NAME
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the + ends up creating an HTML-unsafe value, where this approach will check each piece separate for HTML-safeness before rendering (the result of the yield may already be HTML safe, as it was in the buggy case)

= APP_NAME
- if content_for?(:title)
= ' - '
= yield(:title)

== stylesheet_link_tag 'application', media: 'all'
<!--[if IE 8]>
Expand Down
11 changes: 11 additions & 0 deletions spec/views/layouts/application.html.slim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
end
end

context '<title>' do
it 'does not double-escape HTML in the title tag' do
view.title("Something with 'single quotes'")

render

doc = Nokogiri::HTML(rendered)
expect(doc.at_css('title').text).to eq("login.gov - Something with 'single quotes'")
end
end

context 'session expiration' do
it 'renders a javascript page refresh' do
allow(view).to receive(:user_fully_authenticated?).and_return(false)
Expand Down