diff --git a/app/helpers/blacklight/catalog_helper_behavior.rb b/app/helpers/blacklight/catalog_helper_behavior.rb index 3add99b9c5..131b4bb560 100644 --- a/app/helpers/blacklight/catalog_helper_behavior.rb +++ b/app/helpers/blacklight/catalog_helper_behavior.rb @@ -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 diff --git a/spec/helpers/catalog_helper_spec.rb b/spec/helpers/catalog_helper_spec.rb index 0c2a265a35..b54758c249 100644 --- a/spec/helpers/catalog_helper_spec.rb +++ b/spec/helpers/catalog_helper_spec.rb @@ -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', ['1990 to 1999'.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 > Hierarchy'])).to eq "Folder: Some > Nested > Hierarchy" + end end describe "#render_search_to_page_title" do