Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.
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
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/caching/fragments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
if cache = read_fragment(name, options)
buffer.safe_concat(cache.html_safe)
else
pos = buffer.length
pos = buffer.bytesize
block.call
write_fragment(name, buffer[pos..-1], options)
write_fragment(name, buffer.byteslice(pos..-1), options)
end
else
block.call
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/controller/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,19 @@ def test_fragment_for
assert_equal 'generated till now -> fragment content', buffer
end

def test_fragment_for_bytesize
buffer = "\xC4\x8D"
buffer.force_encoding('ASCII-8BIT')

@controller.fragment_for(buffer, 'bytesize') do
buffer.force_encoding('UTF-8')
buffer << "abc"
end

assert_equal Encoding::UTF_8, buffer.encoding
assert_equal "abc", @store.read('views/bytesize')
end

def test_html_safety
assert_nil @store.read('views/name')
content = 'value'.html_safe
Expand Down