Array#join does not respect ActiveSupport::SafeBuffer #2544

Closed
listrophy opened this Issue Aug 16, 2011 · 1 comment

Comments

Projects
None yet
3 participants
@listrophy

Problem

If all elements of an array are of type ActiveSupport::SafeBuffer, calling #join results in a String rather than an ActiveSupport::SafeBuffer

Steps to Reproduce

require 'spec_helper'

describe 'Array#join' do
  it 'respects ActiveSupport::SafeBuffer' do
    %w(foo bar).map(&:html_safe).join.should be_an(ActiveSupport::SafeBuffer)
  end
end
$ rspec spec/helpers/pages_helper_spec.rb 
F

Failures:

  1) Array#join respects ActiveSupport::SafeBuffer
     Failure/Error: %w(foo bar).map(&:html_safe).join.should be_an(ActiveSupport::SafeBuffer)
       expected "foobar" to be a kind of ActiveSupport::SafeBuffer
...

Considerations

Array#join is used by Array#to_sentence and probably other ActiveSupport helpers. Therefore, an array with html_safe'd html tags will get escaped when used in a view.

@tenderlove

This comment has been minimized.

Show comment Hide comment
@tenderlove

tenderlove Aug 16, 2011

Owner

I'm not sure there is much we can do about this. MRI is hard coded to return String classes when Array#join is called.

See here and here.

Owner

tenderlove commented Aug 16, 2011

I'm not sure there is much we can do about this. MRI is hard coded to return String classes when Array#join is called.

See here and here.

@vijaydev vijaydev closed this Oct 30, 2011

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