From a60d1889744205dbc86ce0e23f8ed04ba7093d23 Mon Sep 17 00:00:00 2001 From: Stefan Daschek Date: Wed, 3 Jul 2013 16:49:34 +0200 Subject: Do not start comment text with stray colon if author is blank --- lib/axlsx/workbook/worksheet/comment.rb | 9 +++++---- test/workbook/worksheet/tc_comment.rb | 11 +++++++++++ 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 << '' - str << '' - str << ' ' - str << '' << ::CGI.escapeHTML(author.to_s) << ': -' + str << '' + unless author.to_s == "" + str << '' + str << "" << ::CGI.escapeHTML(author.to_s) << ":\n" + end str << '' str << '' str << '' << ::CGI.escapeHTML(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 -- cgit v1.2.3