summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStefan Daschek <[email protected]>2013-07-03 16:49:34 +0200
committerStefan Daschek <[email protected]>2013-07-03 16:49:34 +0200
commita60d1889744205dbc86ce0e23f8ed04ba7093d23 (patch)
tree4ff6990a0c95a0ce1f7307466c1ae54e40349a7a
parent7bb62e8870ae369a9b2423c87d5e0875873c3834 (diff)
downloadcaxlsx-a60d1889744205dbc86ce0e23f8ed04ba7093d23.tar.gz
caxlsx-a60d1889744205dbc86ce0e23f8ed04ba7093d23.zip
Do not start comment text with stray colon if author is blank
-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