summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/axlsx/workbook/worksheet/comment.rb9
-rw-r--r--test/workbook/worksheet/tc_comment.rb11
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/comment.rb b/lib/axlsx/workbook/worksheet/comment.rb
index eee2b58a..7035f4cf 100644
--- a/lib/axlsx/workbook/worksheet/comment.rb
+++ b/lib/axlsx/workbook/worksheet/comment.rb
@@ -64,10 +64,11 @@ module Axlsx
def to_xml_string(str = "")
author = @comments.authors[author_index]
str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
- str << '<text><r>'
- str << '<rPr> <b/><color indexed="81"/></rPr>'
- str << '<t>' << ::CGI.escapeHTML(author.to_s) << ':
-</t></r>'
+ str << '<text>'
+ unless author.to_s == ""
+ str << '<r><rPr><b/><color indexed="81"/></rPr>'
+ str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
+ end
str << '<r>'
str << '<rPr><color indexed="81"/></rPr>'
str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb
index 9f30436d..e66abb9a 100644
--- a/test/workbook/worksheet/tc_comment.rb
+++ b/test/workbook/worksheet/tc_comment.rb
@@ -57,5 +57,16 @@ class TestComment < Test::Unit::TestCase
assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1)
end
+ def test_comment_text_contain_author_and_text
+ comment = @ws.add_comment :ref => 'C4', :text => 'some text', :author => 'Bob'
+ doc = Nokogiri::XML(comment.to_xml_string)
+ assert_equal("Bob:\nsome text", doc.xpath("//comment/text").text)
+ end
+
+ def test_comment_text_does_not_contain_stray_colon_if_author_blank
+ comment = @ws.add_comment :ref => 'C5', :text => 'some text', :author => ''
+ doc = Nokogiri::XML(comment.to_xml_string)
+ assert_equal("some text", doc.xpath("//comment/text").text)
+ end
end