From c6a07b6c8e42f7b11fd5f6ca1663299734bf7159 Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Fri, 15 Aug 2014 15:08:24 -0400 Subject: [PATCH] Add test to confirm control characters are removed from shared strings * Commit f8ef8eb78eb4556676b5770c82493e6e6edf7ec8 fixed the shared strings class to automatically sanitize its serialized XML output to remove any control characters. However, this commit did not include tests that the shared strings actually removed the control characters when serializing to an XML string. * This tests confirms that the string with control characters is added to the shared strings, and that the control characters are removed from the string in question when serialized to XML. --- test/workbook/tc_shared_strings_table.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb index e3c9bf7b..79c2ec1d 100644 --- a/test/workbook/tc_shared_strings_table.rb +++ b/test/workbook/tc_shared_strings_table.rb @@ -35,4 +35,18 @@ def test_valid_document assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s) end + def test_remove_control_characters_in_xml_serialization + nasties = "hello\x10\x00\x1C\x1Eworld" + @p.workbook.worksheets[0].add_row [nasties] + + # test that the nasty string was added to the shared strings + assert @p.workbook.shared_strings.unique_cells.has_key?(nasties) + + # test that none of the control characters are in the XML output for shared strings + assert_no_match Axlsx::CONTROL_CHAR_REGEX, @p.workbook.shared_strings.to_xml_string + + # assert that the shared string was normalized to remove the control characters + assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld") + end + end