зеркало из https://github.com/github/ruby.git
[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
This commit is contained in:
Родитель
5359121a56
Коммит
b8084b5cb4
|
@ -50,7 +50,7 @@ class CSV
|
|||
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|
|
||||
|
|
|
@ -20,14 +20,14 @@ module TestCSVWriteConverters
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче