diff -r 789932355683 app/helpers/application_helper.rb
--- a/app/helpers/application_helper.rb Wed Jan 16 07:20:49 2019 +0000
+++ b/app/helpers/application_helper.rb Wed Jan 16 15:40:26 2019 +0300
@@ -724,7 +724,7 @@
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)
diff -r 789932355683 test/fixtures/attachments.yml
--- a/test/fixtures/attachments.yml Wed Jan 16 07:20:49 2019 +0000
+++ b/test/fixtures/attachments.yml Wed Jan 16 15:40:26 2019 +0300
@@ -268,3 +268,17 @@
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
diff -r 789932355683 test/unit/attachment_test.rb
--- a/test/unit/attachment_test.rb Wed Jan 16 07:20:49 2019 +0000
+++ b/test/unit/attachment_test.rb Wed Jan 16 15:40:26 2019 +0300
@@ -410,6 +410,30 @@
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?
diff -r 789932355683 test/unit/helpers/application_helper_test.rb
--- a/test/unit/helpers/application_helper_test.rb Wed Jan 16 07:20:49 2019 +0000
+++ b/test/unit/helpers/application_helper_test.rb Wed Jan 16 15:40:26 2019 +0300
@@ -160,6 +160,16 @@
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 %(),
+ textilizable("!" + string + "!)", :attachments => [attachment])
+ end
+ end
+
def test_attached_images_with_markdown_and_non_ascii_filename
skip unless Object.const_defined?(:Redcarpet)
@@ -170,6 +180,18 @@
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 %(
),
+ textilizable("", :attachments => [attachment])
+ end
+ end
+
def test_attached_images_with_hires_naming
attachment = Attachment.generate!(:filename => 'image@2x.png')
assert_equal %(