Skip to content

Commit

Permalink
Strip markup from html_safe selected facet values in the html title.
Browse files Browse the repository at this point in the history
- E.g., span/data-attributes rendered for selected range facet values by blacklight_range_limit
- Does not affect typical values that are not marked html_safe
- Fixes #2707
- Fixes projectblacklight/blacklight_range_limit#189
  • Loading branch information
seanaery committed Dec 18, 2024
1 parent 6a5f890 commit d1544a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit d1544a9

Please sign in to comment.