Skip to content

Commit

Permalink
always call html_safe on will_paginate result
Browse files Browse the repository at this point in the history
This ensures that the HTML output of `will_paginate` view helper is not
only marked safe in Rails, but in Padrino as well.
  • Loading branch information
mislav committed Sep 16, 2013
1 parent 0da1688 commit 4cb4986
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/will_paginate/view_helpers.rb
Expand Up @@ -91,7 +91,9 @@ def will_paginate(collection, options = {})
end
# render HTML for pagination
renderer.prepare collection, options, self
renderer.to_html
output = renderer.to_html
output = output.html_safe if output.respond_to?(:html_safe)
output
end

# Renders a message containing number of displayed vs. total entries.
Expand Down
2 changes: 1 addition & 1 deletion lib/will_paginate/view_helpers/action_view.rb
Expand Up @@ -30,7 +30,7 @@ def will_paginate(collection = nil, options = {}) #:nodoc:
options = options.symbolize_keys
options[:renderer] ||= LinkRenderer

super(collection, options).try(:html_safe)
super(collection, options)
end

def page_entries_info(collection = nil, options = {}) #:nodoc:
Expand Down
12 changes: 12 additions & 0 deletions spec/view_helpers/base_spec.rb
Expand Up @@ -32,6 +32,18 @@
collection = mock 'Collection', :total_pages => 1
will_paginate(collection).should be_nil
end

it "should call html_safe on result" do
collection = WillPaginate::Collection.new(1, 2, 4)

html = mock 'HTML'
html.expects(:html_safe).returns(html)
renderer = mock 'Renderer'
renderer.stubs(:prepare)
renderer.expects(:to_html).returns(html)

will_paginate(collection, :renderer => renderer).should eql(html)
end
end

describe "pagination_options" do
Expand Down

0 comments on commit 4cb4986

Please sign in to comment.