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

Fix #43 html escaping when layout is false #48

Merged
merged 2 commits into from
Jul 19, 2018
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
2 changes: 1 addition & 1 deletion lib/action_controller/caching/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def render_to_string(controller, body)
end
else
def render_to_string(controller, body)
controller.render_to_string(html: body, layout: true)
controller.render_to_string(html: body.html_safe, layout: true)
end
end

Expand Down
23 changes: 12 additions & 11 deletions test/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ActionCachingTestController < CachingController
layout "talk_from_action"

def index
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s
render plain: @cache_this
end

Expand All @@ -66,17 +66,17 @@ def forbidden
end

def with_layout
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s
render html: @cache_this, layout: true
end

def with_format_and_http_param
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s
render plain: @cache_this
end

def with_symbol_format
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s
render json: { timestamp: @cache_this }
end

Expand Down Expand Up @@ -126,15 +126,15 @@ def streaming
end

def invalid
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s

respond_to do |format|
format.json { render json: @cache_this }
end
end

def accept
@cache_this = MockTime.now.to_f.to_s
@cache_this = CacheContent.to_s

respond_to do |format|
format.html { render html: @cache_this }
Expand Down Expand Up @@ -174,10 +174,11 @@ def render(options)
end
end

class MockTime < Time
# Let Time spicy to assure that Time.now != Time.now
def to_f
super + rand
class CacheContent
def self.to_s
# Let Time spicy to assure that Time.now != Time.now
time = Time.now.to_f + rand
(time.to_s + "<div />").html_safe
end
end

Expand Down Expand Up @@ -391,7 +392,7 @@ def test_action_cache_with_store_options
get "/action_caching_test", to: "action_caching_test#index"
end

MockTime.expects(:now).returns(12345).once
CacheContent.expects(:to_s).returns('12345.0').once
@controller.expects(:read_fragment).with("hostname.com/action_caching_test", expires_in: 1.hour).once
@controller.expects(:write_fragment).with("hostname.com/action_caching_test", "12345.0", expires_in: 1.hour).once
get :index
Expand Down