ruby-changes:62285
From: Sutou <ko1@a...>
Date: Mon, 20 Jul 2020 03:35:35 +0900 (JST)
Subject: [ruby-changes:62285] b8084b5cb4 (master): [ruby/csv] Fix a bug that write_nil_value or write_empty_value don't work with non String
https://git.ruby-lang.org/ruby.git/commit/?id=b8084b5cb4 From b8084b5cb4e20d463938b518dd12f91290c3fb1a Mon Sep 17 00:00:00 2001 From: Sutou Kouhei <kou@c...> Date: Sun, 17 May 2020 11:51:06 +0900 Subject: [ruby/csv] Fix a bug that write_nil_value or write_empty_value don't work with non String GitHub: fix GH-123 Reported by asm256. Thanks!!! https://github.com/ruby/csv/commit/b4492139be diff --git a/lib/csv/fields_converter.rb b/lib/csv/fields_converter.rb index a751c9e..178ffb3 100644 --- a/lib/csv/fields_converter.rb +++ b/lib/csv/fields_converter.rb @@ -50,7 +50,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/fields_converter.rb#L50 fields.collect.with_index do |field, index| if field.nil? field = @nil_value - elsif field.empty? + elsif field.is_a?(String) and field.empty? field = @empty_value unless @empty_value_is_empty_string end @converters.each do |converter| diff --git a/test/csv/write/test_converters.rb b/test/csv/write/test_converters.rb index a93b104..0e0080b 100644 --- a/test/csv/write/test_converters.rb +++ b/test/csv/write/test_converters.rb @@ -20,14 +20,14 @@ module TestCSVWriteConverters https://github.com/ruby/ruby/blob/trunk/test/csv/write/test_converters.rb#L20 end def test_nil_value - assert_equal(%Q[a,NaN,c\n], - generate_line(["a", nil, "c"], + assert_equal(%Q[a,NaN,29\n], + generate_line(["a", nil, 29], write_nil_value: "NaN")) end def test_empty_value - assert_equal(%Q[a,,c\n], - generate_line(["a", "", "c"], + assert_equal(%Q[a,,29\n], + generate_line(["a", "", 29], write_empty_value: nil)) end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/