Defect #30441 » attachments-unicode-case.diff
| app/helpers/application_helper.rb Wed Jan 16 07:20:49 2019 +0000 → app/helpers/application_helper.rb Wed Jan 16 15:40:26 2019 +0300 | ||
|---|---|---|
|
attachments += obj.attachments if obj.respond_to?(:attachments)
|
||
|
if attachments.present?
|
||
|
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
||
|
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
||
|
filename, ext, alt, alttext = $1, $2, $3, $4
|
||
|
# search for the picture in attachments
|
||
|
if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
|
||
|
image_url = download_named_attachment_url(found, found.filename, :only_path => only_path)
|
||
| test/fixtures/attachments.yml Wed Jan 16 07:20:49 2019 +0000 → test/fixtures/attachments.yml Wed Jan 16 15:40:26 2019 +0300 | ||
|---|---|---|
|
filename: root_attachment.txt
|
||
|
filesize: 54
|
||
|
author_id: 2
|
||
|
attachments_021:
|
||
|
content_type: image/png
|
||
|
downloads: 0
|
||
|
created_on: 2011-02-23 16:14:50 +09:00
|
||
|
disk_filename: 101223161450_testfile_2.png
|
||
|
disk_directory: "2010/12"
|
||
|
container_id: 14
|
||
|
digest: 6bc2963e8d7ea0d3e68d12d1fba3d6ca
|
||
|
id: 21
|
||
|
container_type: Issue
|
||
|
description: ""
|
||
|
filename: TestТест.png
|
||
|
filesize: 3582
|
||
|
author_id: 2
|
||
| test/unit/attachment_test.rb Wed Jan 16 07:20:49 2019 +0000 → test/unit/attachment_test.rb Wed Jan 16 15:40:26 2019 +0300 | ||
|---|---|---|
|
set_tmp_attachments_directory
|
||
|
end
|
||
|
def test_latest_should_get_with_unicode_downcase
|
||
|
set_fixtures_attachments_directory
|
||
|
# first unicode letter (\xd0\xa2) is uppercase
|
||
|
string = "Test\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82.png".force_encoding("UTF-8")
|
||
|
assert_equal true, string.valid_encoding?
|
||
|
a1 = Attachment.find(21)
|
||
|
assert_equal string, a1.filename
|
||
|
# ensure that string#casecmp fails to compare unicode strings case-sensitive
|
||
|
assert_not_equal 0, string.casecmp(string.downcase)
|
||
|
# search with exact string succeeds
|
||
|
la1 = Attachment.latest_attach([a1], string)
|
||
|
assert_not_nil la1
|
||
|
# using downcase should fail because of casecmp
|
||
|
la2 = Attachment.latest_attach([a1], string.downcase)
|
||
|
assert_nil la2
|
||
|
set_tmp_attachments_directory
|
||
|
end
|
||
|
def test_latest_attach_should_not_error_with_string_with_invalid_encoding
|
||
|
string = "width:50\xFE-Image.jpg".force_encoding('UTF-8')
|
||
|
assert_equal false, string.valid_encoding?
|
||
| test/unit/helpers/application_helper_test.rb Wed Jan 16 07:20:49 2019 +0000 → test/unit/helpers/application_helper_test.rb Wed Jan 16 15:40:26 2019 +0300 | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_attached_images_with_textile_and_uppercase_non_ascii_filename
|
||
|
# first unicode letter (\xd0\xa2) is uppercase
|
||
|
string = "Test\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82.png".force_encoding("UTF-8")
|
||
|
attachment = Attachment.generate!(:filename => string)
|
||
|
with_settings :text_formatting => 'textile' do
|
||
|
assert_include %(<img src="/attachments/download/#{attachment.id}/Test%D0%A2%D0%B5%D1%81%D1%82.png" alt="" />),
|
||
|
textilizable("!" + string + "!)", :attachments => [attachment])
|
||
|
end
|
||
|
end
|
||
|
def test_attached_images_with_markdown_and_non_ascii_filename
|
||
|
skip unless Object.const_defined?(:Redcarpet)
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_attached_images_with_markdown_and_uppercase_non_ascii_filename
|
||
|
skip unless Object.const_defined?(:Redcarpet)
|
||
|
# first unicode letter (\xd0\xa2) is uppercase
|
||
|
string = "Test\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82.png".force_encoding("UTF-8")
|
||
|
attachment = Attachment.generate!(:filename => string)
|
||
|
with_settings :text_formatting => 'markdown' do
|
||
|
assert_include %(<img src="/attachments/download/#{attachment.id}/Test%D0%A2%D0%B5%D1%81%D1%82.png" alt="" />),
|
||
|
textilizable("", :attachments => [attachment])
|
||
|
end
|
||
|
end
|
||
|
def test_attached_images_with_hires_naming
|
||
|
attachment = Attachment.generate!(:filename => 'image@2x.png')
|
||
|
assert_equal %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" /></p>),
|
||