提交 0c52ae6d 编写于 作者: A Aman Gupta

Merge pull request #39 from github/write-fragment-fix

Fix fragment caching in mixed encoding scenario
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册