summaryrefslogtreecommitdiffhomepage
path: root/test/drawing
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2019-12-29 19:11:05 +0100
committerStefan Daschek <[email protected]>2019-12-29 19:11:05 +0100
commite65ec48bc86379efed0c1b87a13bff14930416d5 (patch)
treeacda1d6f5dbaccb828d2192c4f28cdac56c49785 /test/drawing
parent0a223011a26949ddc00eba882005daee7afeb6a6 (diff)
downloadcaxlsx-e65ec48bc86379efed0c1b87a13bff14930416d5.tar.gz
caxlsx-e65ec48bc86379efed0c1b87a13bff14930416d5.zip
Escape special characters in charts (#40)
Fixes #37
Diffstat (limited to 'test/drawing')
-rw-r--r--test/drawing/tc_series_title.rb21
-rw-r--r--test/drawing/tc_title.rb16
2 files changed, 37 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