diff options
| author | Zsolt Kozaroczy <[email protected]> | 2019-12-29 19:11:05 +0100 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2019-12-29 19:11:05 +0100 |
| commit | e65ec48bc86379efed0c1b87a13bff14930416d5 (patch) | |
| tree | acda1d6f5dbaccb828d2192c4f28cdac56c49785 /test | |
| parent | 0a223011a26949ddc00eba882005daee7afeb6a6 (diff) | |
| download | caxlsx-e65ec48bc86379efed0c1b87a13bff14930416d5.tar.gz caxlsx-e65ec48bc86379efed0c1b87a13bff14930416d5.zip | |
Escape special characters in charts (#40)
Fixes #37
Diffstat (limited to 'test')
| -rw-r--r-- | test/drawing/tc_series_title.rb | 21 | ||||
| -rw-r--r-- | test/drawing/tc_title.rb | 16 | ||||
| -rw-r--r-- | test/tc_axlsx.rb | 6 |
3 files changed, 43 insertions, 0 deletions
diff --git a/test/drawing/tc_series_title.rb b/test/drawing/tc_series_title.rb index 90427e9c..b85aece3 100644 --- a/test/drawing/tc_series_title.rb +++ b/test/drawing/tc_series_title.rb @@ -30,4 +30,25 @@ class TestSeriesTitle < Test::Unit::TestCase assert(@title.text == "one") end + def test_to_xml_string_for_special_characters + @chart.add_series(title: @title, data: [3, 7], labels: ['A', 'B']) + + @title.text = "&><'\"" + + doc = Nokogiri::XML(@chart.to_xml_string) + errors = doc.errors + assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + end + + def test_to_xml_string_for_special_characters_in_cell + @chart.add_series(title: @title, data: [3, 7], labels: ['A', 'B']) + + cell = @row.cells.first + cell.value = "&><'\"" + @title.cell = cell + + doc = Nokogiri::XML(@chart.to_xml_string) + errors = doc.errors + assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + end end diff --git a/test/drawing/tc_title.rb b/test/drawing/tc_title.rb index 95e44602..cdbd87e1 100644 --- a/test/drawing/tc_title.rb +++ b/test/drawing/tc_title.rb @@ -51,4 +51,20 @@ class TestTitle < Test::Unit::TestCase assert_equal(1, doc.xpath('//c:v[text()="one"]').size) end + def test_to_xml_string_for_special_characters + @chart.title.text = "&><'\"" + doc = Nokogiri::XML(@chart.to_xml_string) + errors = doc.errors + assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + end + + def test_to_xml_string_for_special_characters_in_cell + cell = @row.cells.first + cell.value = "&><'\"" + + @chart.title.cell = cell + doc = Nokogiri::XML(@chart.to_xml_string) + errors = doc.errors + assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + end end diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb index 3d6a2e70..55bca1f4 100644 --- a/test/tc_axlsx.rb +++ b/test/tc_axlsx.rb @@ -24,8 +24,14 @@ class TestAxlsx < Test::Unit::TestCase def test_trust_input_can_be_set_to_true + # Class variables like this are not reset between test runs, so we have + # to save and restore the original value manually. + old = Axlsx.trust_input + Axlsx.trust_input = true assert_equal true, Axlsx.trust_input + + Axlsx.trust_input = old end def test_cell_range_relative p = Axlsx::Package.new |
