diff options
| -rw-r--r-- | lib/axlsx/drawing/title.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_title.rb | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index 002ae94f..d3100d43 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -61,7 +61,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '<c:title>' - unless @text.empty? + unless @text.empty? && @cell.nil? clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s)) str << '<c:tx>' if @cell.is_a?(Cell) diff --git a/test/drawing/tc_title.rb b/test/drawing/tc_title.rb index cdbd87e1..eb549b35 100644 --- a/test/drawing/tc_title.rb +++ b/test/drawing/tc_title.rb @@ -47,8 +47,18 @@ class TestTitle < Test::Unit::TestCase def test_to_xml_string_cell @chart.title.cell = @row.cells.first doc = Nokogiri::XML(@chart.to_xml_string) + assert_equal("'Sheet1'!$A$1:$A$1", doc.xpath('//c:strRef/c:f').text) assert_equal(1, doc.xpath('//c:strCache').size) - assert_equal(1, doc.xpath('//c:v[text()="one"]').size) + assert_equal('one', doc.xpath('//c:strCache/c:pt//c:v').text) + end + + def test_to_xml_string_empty_cell + @row.cells.first.value = "" + @chart.title.cell = @row.cells.first + doc = Nokogiri::XML(@chart.to_xml_string) + assert_equal("'Sheet1'!$A$1:$A$1", doc.xpath('//c:strRef/c:f').text) + assert_equal(1, doc.xpath('//c:strCache').size) + assert_equal('', doc.xpath('//c:strCache/c:pt//c:v').text) end def test_to_xml_string_for_special_characters |
