Skip to content

Commit

Permalink
FacettedAttributeRenderer should singly escape, not double
Browse files Browse the repository at this point in the history
There is no need to escape the param _before_ passing to a Rails route helper,
the rails route helper will escape for you. Escaping first results in _double_
escaped content, and a broken search link.
  • Loading branch information
jrochkind authored and jcoyne committed May 25, 2017
1 parent de27154 commit c3d5cfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -8,7 +8,7 @@ def li_value(value)
end

def search_path(value)
Rails.application.routes.url_helpers.search_catalog_path(:"f[#{search_field}][]" => ERB::Util.h(value))
Rails.application.routes.url_helpers.search_catalog_path(:"f[#{search_field}][]" => value)
end

def search_field
Expand Down
11 changes: 11 additions & 0 deletions spec/renderers/hyrax/renderers/faceted_attribute_renderer_spec.rb
Expand Up @@ -18,4 +18,15 @@
it { expect(renderer).not_to be_microdata(field) }
it { expect(subject).to be_equivalent_to(expected) }
end

describe "href generated" do
describe "escaping" do
let(:renderer) { described_class.new(field, ['John & Bob']) }
let(:rendered_link) { Nokogiri::HTML(renderer.render).at_css("a") }
let(:rendered_link_query) { URI.parse(rendered_link['href']).query }
it "escapes content properly" do
expect(rendered_link_query).to eq "#{CGI.escape('f[name_sim][]')}=#{CGI.escape('John & Bob')}"
end
end
end
end

0 comments on commit c3d5cfc

Please sign in to comment.