test-30441.patch

Go MAEDA, 2019-04-12 06:27

Download (2.53 KB)

View differences:

app/helpers/application_helper.rb
774 774
    attachments += obj.attachments if obj.respond_to?(:attachments)
775 775
    if attachments.present?
776 776
      text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
777
        filename, ext, alt, alttext = $1.downcase, $2, $3, $4
777
        filename, ext, alt, alttext = $1, $2, $3, $4
778 778
        # search for the picture in attachments
779 779
        if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
780 780
          image_url = download_named_attachment_url(found, found.filename, :only_path => only_path)
test/helpers/application_helper_test.rb
156 156
  end
157 157

  
158 158
  def test_attached_images_with_textile_and_non_ascii_filename
159
    attachment = Attachment.generate!(:filename => 'café.jpg')
159
    to_test = {
160
      'CAFÉ.JPG' => 'CAF%C3%89.JPG',
161
      'crème.jpg' => 'cr%C3%A8me.jpg',
162
    }
160 163
    with_settings :text_formatting => 'textile' do
161
      assert_include %(<img src="/attachments/download/#{attachment.id}/caf%C3%A9.jpg" alt="" />),
162
        textilizable("!café.jpg!)", :attachments => [attachment])
164
      to_test.each do |filename, result|
165
        attachment = Attachment.generate!(:filename => filename)
166
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />), textilizable("!#{filename}!", :attachments => [attachment])
167
      end
163 168
    end
164 169
  end
165 170

  
166 171
  def test_attached_images_with_markdown_and_non_ascii_filename
167 172
    skip unless Object.const_defined?(:Redcarpet)
168 173

  
169
    attachment = Attachment.generate!(:filename => 'café.jpg')
174
    to_test = {
175
      'CAFÉ.JPG' => 'CAF%C3%89.JPG',
176
      'crème.jpg' => 'cr%C3%A8me.jpg',
177
    }
170 178
    with_settings :text_formatting => 'markdown' do
171
      assert_include %(<img src="/attachments/download/#{attachment.id}/caf%C3%A9.jpg" alt="" />),
172
        textilizable("![](café.jpg)", :attachments => [attachment])
179
      to_test.each do |filename, result|
180
        attachment = Attachment.generate!(:filename => filename)
181
        assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />), textilizable("![](#{filename})", :attachments => [attachment])
182
      end
173 183
    end
174 184
  end
175 185