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

Strip markup from html_safe selected facet values in the html title. #3464

Merged
merged 1 commit into from
Jan 21, 2025
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
6 changes: 5 additions & 1 deletion app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def render_search_to_page_title_filter(facet, values)
facet_config = facet_configuration_for_field(facet)
filter_label = facet_field_label(facet_config.key)
filter_value = if values.size < 3
values.map { |value| facet_item_presenter(facet_config, value, facet).label }.to_sentence
values.map do |value|
label = facet_item_presenter(facet_config, value, facet).label
label = strip_tags(label) if label.html_safe?
label
end.to_sentence
else
t('blacklight.search.page_title.many_constraint_values', values: values.size)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/catalog_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ def mock_response args
it "renders a facet with more than two values" do
expect(helper.render_search_to_page_title_filter('foo', %w[bar baz foobar])).to eq "Foo: 3 selected"
end

it "strips tags from html_safe values" do
expect(helper.render_search_to_page_title_filter('Year', ['<span class="from" data-blrl-begin="1990">1990</span> to <span class="to" data-blrl-end="1999">1999</span>'.html_safe])).to eq "Year: 1990 to 1999"
end

it "does not strip tags from non-html_safe values" do
expect(helper.render_search_to_page_title_filter('Folder', ['Some > Nested > <span>Hierarchy</span>'])).to eq "Folder: Some > Nested > <span>Hierarchy</span>"
end
end

describe "#render_search_to_page_title" do
Expand Down
Loading