Skip to content

Commit

Permalink
Merge pull request #1546 from sikachu/31safebuffer
Browse files Browse the repository at this point in the history
Fix failing ActionPack tests on 3-1-stable
  • Loading branch information
josevalim committed Jun 8, 2011
2 parents 2664897 + 719e05d commit 623c16f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion actionpack/lib/action_view/helpers/cache_helper.rb
Expand Up @@ -51,7 +51,13 @@ def fragment_for(name = {}, options = nil, &block) #:nodoc:
# This dance is needed because Builder can't use capture
pos = output_buffer.length
yield
fragment = output_buffer.slice!(pos..-1)
if output_buffer.is_a?(ActionView::OutputBuffer)
safe_output_buffer = output_buffer.to_str
fragment = safe_output_buffer.slice!(pos..-1)
self.output_buffer = ActionView::OutputBuffer.new(safe_output_buffer)
else
fragment = output_buffer.slice!(pos..-1)
end
controller.write_fragment(name, fragment, options)
end
end
Expand Down
8 changes: 5 additions & 3 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -255,14 +255,16 @@ def word_wrap(text, *args)
# simple_format("<span>I'm allowed!</span> It's true.", {}, :sanitize => false)
# # => "<p><span>I'm allowed!</span> It's true.</p>"
def simple_format(text, html_options={}, options={})
text = ''.html_safe if text.nil?
text = text ? text.to_str : ''
text = text.dup if text.frozen?
start_tag = tag('p', html_options, true)
text = sanitize(text) unless options[:sanitize] == false
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text.html_safe.safe_concat("</p>")
text.concat("</p>")
text = sanitize(text) unless options[:sanitize] == false
text
end

# Creates a Cycle object whose _to_s_ method cycles through elements of an
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/url_helper.rb
Expand Up @@ -497,14 +497,14 @@ def mail_to(email_address, name = nil, html_options = {})
}.compact
extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&'))

email_address_obfuscated = email_address.dup
email_address_obfuscated = email_address.to_str
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
case encode
when "javascript"
string = ''
html = content_tag("a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe))
html = escape_javascript(html)
html = escape_javascript(html.to_str)
"document.write('#{html}');".each_byte do |c|
string << sprintf("%%%x", c)
end
Expand Down

0 comments on commit 623c16f

Please sign in to comment.