Patch #28112

CsvTest fails due to a regression in Ruby 2.5

Added by Sho HASHIMOTO about 5 years ago. Updated over 4 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Ruby support
Target version:-

Description

Ruby 2.5.0 at r17185 don't pass csv_test.rb:29.

Failure:
CsvTest#test_should_include_bom_when_utf8_encoded [/Users/sho-h/local/src/redmine/redmine.sho-h/test/unit/lib/redmine/export/csv_test.rb:29]:
Expected false to be truthy.

Maybe, the reason is regression in 2.5.0.

$ cat csvtest.rb

require 'csv'
bom = "\xEF\xBB\xBF" 
res1_1 = bom.dup
res1_2 = CSV.generate(res1_1, encoding: "UTF-8") {|csv| csv << %w(Foo Bar)}
p [bom, res1_1, res1_2]

res2_1 = "aa,bb" 
res2_2 = CSV.generate(res2_1, encoding: "UTF-8") {|csv| csv << %w(Foo Bar)}
p [bom, res2_1, res2_2]

$ rbenv each ruby -v csvtest.rb | more
...
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-darwin15]
["<U+FEFF>", "<U+FEFF>Foo,Bar\n", "<U+FEFF>Foo,Bar\n"]
["<U+FEFF>", "aa,bbFoo,Bar\n", "aa,bbFoo,Bar\n"]
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin15]
["<U+FEFF>", "<U+FEFF>Foo,Bar\n", "<U+FEFF>Foo,Bar\n"]
["<U+FEFF>", "aa,bbFoo,Bar\n", "aa,bbFoo,Bar\n"]
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin15]
["<U+FEFF>", "Foo,Bar\n", "Foo,Bar\n"]
["<U+FEFF>", "Foo,Bar\n", "Foo,Bar\n"]

This problem was already reported below.

I attach patch to fix this problem. This patch don't use CSV.generate's first argument.

redmine_with_ruby250.patch Magnifier (954 Bytes) Sho HASHIMOTO, 2018-01-31 12:08


Related issues

Related to Redmine - Defect #28689: csv 1.0.2 gem breaks ImportsControllerTest Closed
Blocks Redmine - Feature #27849: Ruby 2.5 support Closed

Associated revisions

Revision 17245
Added by Go MAEDA almost 5 years ago

CsvTest#test_should_include_bom_when_utf8_encoded fails due to a regression in Ruby 2.5.0 (#28112).

Contributed by Sho HASHIMOTO.

Revision 17696
Added by Go MAEDA over 4 years ago

Don't explicitly install csv gem in Ruby 2.6 (#30118).

Redmine installs csv gem since r17245 as a workaround for a bug of csv 1.0.0 which is bundled with Ruby 2.5 (see #28112). But in Ruby 2.6, installing the gem is not necessary because the bundled csv gem was updated to 3.0.

History

#1 Updated by Go MAEDA about 5 years ago

#2 Updated by Sho HASHIMOTO almost 5 years ago

Above problem fixed by csv gem 1.0.1.

#3 Updated by Go MAEDA almost 5 years ago

Sho HASHIMOTO wrote:

Above problem fixed by csv gem 1.0.1.

Thank you for looking into this issue. Do you think we can fix this issue by changing Gemfile as follows?

Index: Gemfile
===================================================================
--- Gemfile    (revision 17236)
+++ Gemfile    (working copy)
@@ -13,6 +13,7 @@
 gem "roadie", "~> 3.2.1" 
 gem "mimemagic" 
 gem "mail", "~> 2.6.4" 
+gem "csv", "~> 1.0.1" if RUBY_VERSION >= "2.5" 

 gem "nokogiri", "~> 1.8.0" 
 gem "i18n", "~> 0.7.0" 

#4 Updated by Sho HASHIMOTO almost 5 years ago

Thank you for looking into this issue. Do you think we can fix this issue by changing Gemfile as follows?

I think so. My patch is not needed any more. :)
I checked unit test only appending below line to Gemfile.local. My Ruby was 2.5.0.

gem 'csv', '1.0.1'

#5 Updated by Go MAEDA almost 5 years ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the fix. Thank you for working on this issue.

#6 Updated by Go MAEDA almost 5 years ago

  • Related to Defect #28689: csv 1.0.2 gem breaks ImportsControllerTest added

#7 Updated by Go MAEDA over 4 years ago

  • Subject changed from Ruby 2.5.0 don't pass csv_test.rb to CsvTest fails due to a regression in Ruby 2.5

Also available in: Atom PDF