rails safebuffer change causes fragment_for failures #1537

Closed
cmeiklejohn opened this Issue Jun 8, 2011 · 7 comments

Comments

Projects
None yet
4 participants
@cmeiklejohn
Contributor

cmeiklejohn commented Jun 8, 2011

Finished in 0.729945 seconds.

  1) Error:
test_fragment_caching(FunctionalFragmentCachingTest):
ActionView::Template::Error: Cannot modify SafeBuffer in place
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb:121:in `slice!'
    /home/cmeiklejohn/Repositories/rails/actionpack/lib/action_view/helpers/cache_helper.rb:54:in `fragment_for'
--
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run'

  2) Error:
test_fragment_caching_in_partials(FunctionalFragmentCachingTest):
ActionView::Template::Error: Cannot modify SafeBuffer in place
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb:121:in `slice!'
    /home/cmeiklejohn/Repositories/rails/actionpack/lib/action_view/helpers/cache_helper.rb:54:in `fragment_for'
--
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run'

  3) Error:
test_html_formatted_fragment_caching(FunctionalFragmentCachingTest):
ActionView::Template::Error: Cannot modify SafeBuffer in place
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb:121:in `slice!'
    /home/cmeiklejohn/Repositories/rails/actionpack/lib/action_view/helpers/cache_helper.rb:54:in `fragment_for'
--
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run'

  4) Error:
test_render_inline_before_fragment_caching(FunctionalFragmentCachingTest):
ActionView::Template::Error: Cannot modify SafeBuffer in place
    /home/cmeiklejohn/Repositories/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb:121:in `slice!'
    /home/cmeiklejohn/Repositories/rails/actionpack/lib/action_view/helpers/cache_helper.rb:54:in `fragment_for'
@cmeiklejohn

This comment has been minimized.

Show comment Hide comment
@cmeiklejohn

cmeiklejohn Jun 8, 2011

Contributor

I'm seeing this on 3.0.8 and master.

Contributor

cmeiklejohn commented Jun 8, 2011

I'm seeing this on 3.0.8 and master.

@glanotte

This comment has been minimized.

Show comment Hide comment
@glanotte

glanotte Jun 8, 2011

I was experiencing a similar issue, coming from haml. I updated haml from 3.1.1 to 3.1.2 and that resolved my issue.

glanotte commented Jun 8, 2011

I was experiencing a similar issue, coming from haml. I updated haml from 3.1.1 to 3.1.2 and that resolved my issue.

@cmeiklejohn

This comment has been minimized.

Show comment Hide comment
@cmeiklejohn

cmeiklejohn Jun 8, 2011

Contributor

Fixes pending merge in 3-1, master; merged in 3-0.

Contributor

cmeiklejohn commented Jun 8, 2011

Fixes pending merge in 3-1, master; merged in 3-0.

@cmeiklejohn cmeiklejohn closed this Jun 8, 2011

@lhahne

This comment has been minimized.

Show comment Hide comment
@lhahne

lhahne Jul 14, 2011

I'm having almost the same problem with Rails 3.0.9. I use slim templates which might be part of the cause as execution reaches the else branch of

          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

This throws a Cannot modify SafeBuffer in place. A quick fix is to remove the exclamation mark that follows the latter slice. The has been changed in Rails 3.1 but it still looks like it would be affected by this.

lhahne commented Jul 14, 2011

I'm having almost the same problem with Rails 3.0.9. I use slim templates which might be part of the cause as execution reaches the else branch of

          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

This throws a Cannot modify SafeBuffer in place. A quick fix is to remove the exclamation mark that follows the latter slice. The has been changed in Rails 3.1 but it still looks like it would be affected by this.

@cmeiklejohn

This comment has been minimized.

Show comment Hide comment
@cmeiklejohn

cmeiklejohn Jul 14, 2011

Contributor

I think that:

  if output_buffer.is_a?(ActionView::OutputBuffer)

needs to be changed to:

  if output_buffer.is_a?(ActiveSupport::SafeBuffer)

Can you test and see if that fixes it, if so, I'll reopen the issue and update the commits.

Contributor

cmeiklejohn commented Jul 14, 2011

I think that:

  if output_buffer.is_a?(ActionView::OutputBuffer)

needs to be changed to:

  if output_buffer.is_a?(ActiveSupport::SafeBuffer)

Can you test and see if that fixes it, if so, I'll reopen the issue and update the commits.

@dmathieu

This comment has been minimized.

Show comment Hide comment
@dmathieu

dmathieu Jul 14, 2011

Contributor

The fact that an object is an ActiveSupport::SafeBuffer does not guarantee that it's safe. You should use :

output_buffer.html_safe?
Contributor

dmathieu commented Jul 14, 2011

The fact that an object is an ActiveSupport::SafeBuffer does not guarantee that it's safe. You should use :

output_buffer.html_safe?
@lhahne

This comment has been minimized.

Show comment Hide comment
@lhahne

lhahne Jul 15, 2011

I fixed this in #2080

lhahne commented Jul 15, 2011

I fixed this in #2080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment