Compare commits

...

10 Commits

Author SHA1 Message Date
Aman Gupta
f63b0340ff github34 2014-01-08 21:04:30 -08:00
Aman Gupta
7224ee1419 Merge pull request #37 from github/erb-freeze
Freeze ERB string literals
2014-01-08 20:33:01 -08:00
Aman Gupta
0c52ae6df3 Merge pull request #39 from github/write-fragment-fix
Fix fragment caching in mixed encoding scenario
2014-01-08 20:32:40 -08:00
Aman Gupta
f8b7cd2df7 Merge pull request #40 from github/ruby-2.1
Ruby 2.1
2014-01-08 20:32:12 -08:00
Aman Gupta
c73ba86136 use new 2.1 api 2014-01-08 18:03:55 -08:00
Aman Gupta
98fa5dd465 build on ruby 2.1 2014-01-08 17:46:13 -08:00
Mislav Marohnić
fa41bedf6b Don't rely on default encoding always being ASCII-8BIT 2014-01-08 17:41:17 -08:00
Aman Gupta
0a8282c557 freeze literals 2014-01-08 17:28:31 -08:00
Mislav Marohnić
d4a4facfcc Add test for extracting the cache fragment with mixed encodings 2014-01-08 17:12:18 -08:00
Aman Gupta
dd4146854a Fix fragment caching in mixed encodings scenario
To reduce ambiguity between char- and byte-based operations, explicitly
do byte operations when extracting the fragment that needs to be cached.
2014-01-08 16:35:55 -08:00
6 changed files with 24 additions and 7 deletions

View File

@@ -1 +1 @@
2.3.14.github33
2.3.14.github34

View File

@@ -39,9 +39,9 @@ module ActionController #: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

View File

@@ -17,7 +17,7 @@ module ActionView
src << "@output_buffer.safe_append='"
src << "\n" * @newline_pending if @newline_pending > 0
src << escape_text(text)
src << "';"
src << "'.freeze;"
@newline_pending = 0
end
@@ -63,7 +63,7 @@ module ActionView
def flush_newline_if_pending(src)
if @newline_pending > 0
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}';"
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
@newline_pending = 0
end
end

View File

@@ -622,6 +622,19 @@ class FragmentCachingTest < ActionController::TestCase
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

View File

@@ -299,7 +299,11 @@ HELP
# Evaluate any assignments in a temporary, throwaway binding.
vars = template_options[:assigns] || {}
b = template_options[:binding] || binding
vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
if b.respond_to?(:local_variable_set)
vars.each { |k,v| b.local_variable_set(k, v) }
else
vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
end
# Render the source file with the temporary binding.
ERB.new(file.read, nil, '-').result(b)

View File

@@ -4,4 +4,4 @@ set -x
set -e
script/cibuild-on 1.9.3-p231-tcs-github
script/cibuild-on 2.0.0-github
script/cibuild-on 2.1.0-github