Skip to content

Commit

Permalink
Encode empty values
Browse files Browse the repository at this point in the history
The original library skips processing of empty cells, but this behavior
is not desirable for us. There is an [issue reported][1] about it and a
[PR fixing it][2], but the upstream author has not acted on it.

This is the reason we decided to fork the repository and patch it
manually. Credit goes to the patch's author for his work.

JRVS-306

[1]: felixbuenemann#43
[2]: paladinsoftware#2
  • Loading branch information
sturmer committed Mar 4, 2021
1 parent 779acbb commit b352d50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions lib/xlsxtream/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ def to_xml
else
value = value.to_s

unless value.empty? # no xml output for for empty strings
value = value.encode(ENCODING) if value.encoding != ENCODING

if @sst
xml << %Q{<c r="#{cid}" t="s"><v>#{@sst[value]}</v></c>}
else
xml << %Q{<c r="#{cid}" t="inlineStr"><is><t>#{XML.escape_value(value)}</t></is></c>}
end
value = value.encode(ENCODING) if value.encoding != ENCODING

if @sst
xml << %Q{<c r="#{cid}" t="s"><v>#{@sst[value]}</v></c>}
else
xml << %Q{<c r="#{cid}" t="inlineStr"><is><t>#{XML.escape_value(value)}</t></is></c>}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/xlsxtream/row_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Xlsxtream
class RowTest < Minitest::Test
def test_empty_column
row = Row.new([nil], 1)
expected = '<row r="1"></row>'
expected = '<row r="1"><c r="A1" t="inlineStr"><is><t></t></is></c></row>'
actual = row.to_xml
assert_equal expected, actual
end
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_string_column_with_shared_string_table

def test_multiple_columns
row = Row.new(['foo', nil, 23], 1)
expected = '<row r="1"><c r="A1" t="inlineStr"><is><t>foo</t></is></c><c r="C1" t="n"><v>23</v></c></row>'
expected = '<row r="1"><c r="A1" t="inlineStr"><is><t>foo</t></is></c><c r="B1" t="inlineStr"><is><t></t></is></c><c r="C1" t="n"><v>23</v></c></row>'
actual = row.to_xml
assert_equal expected, actual
end
Expand Down

0 comments on commit b352d50

Please sign in to comment.