Skip to content

Commit

Permalink
Add test to confirm control characters are removed from shared strings
Browse files Browse the repository at this point in the history
* Commit f8ef8eb 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.
  • Loading branch information
tcannonfodder committed Aug 15, 2014
1 parent f8ef8eb commit c6a07b6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/workbook/tc_shared_strings_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6a07b6

Please sign in to comment.