Skip to content

Commit

Permalink
Ensure the value set for @page_title is html_safe
Browse files Browse the repository at this point in the history
so that characters such as "'" aren't double escaped
  • Loading branch information
jcoyne committed Feb 13, 2014
1 parent 006be98 commit 96d513e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Expand Up @@ -274,6 +274,13 @@ def document_heading document=nil
render_field_value(document[blacklight_config.view_config(:show).title_field] || document.id)
end

##
# Assign the @page_title instance variable to its default value
def document_page_title
t('blacklight.search.show.title_html', :document_title => document_show_html_title, :application_name => application_name)
end


##
# Get the document's "title" to display in the <title> element.
# (by default, use the #document_heading)
Expand Down
3 changes: 1 addition & 2 deletions app/views/catalog/show.html.erb
Expand Up @@ -2,8 +2,7 @@

<%= render 'previous_next_doc' %>
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name) -%>
<% @page_title = document_page_title %>
<% content_for(:head) { render_link_rel_alternates } -%>
<%# this should be in a partial -%>

Expand Down
2 changes: 1 addition & 1 deletion config/locales/blacklight.en.yml
Expand Up @@ -194,7 +194,7 @@ en:
index:
label: '%{label}:'
show:
title: '%{document_title} - %{application_name}'
title_html: '%{document_title} - %{application_name}'
label: '%{label}:'
rss_feed: 'RSS for results'
atom_feed: 'Atom for results'
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Expand Up @@ -216,6 +216,15 @@ def mock_document_app_helper_url *args
end
end

describe "document_page_title" do
before do
helper.stub(:document_show_html_title => 'Document title')
end
subject { helper.document_page_title }
it { should == "Document title - Blacklight" }
it { should be_html_safe }
end

describe "render_document_show_field_value" do
before do
@config = Blacklight::Configuration.new.configure do |config|
Expand Down

0 comments on commit 96d513e

Please sign in to comment.