diff options
| author | Randy Morgan <[email protected]> | 2012-06-18 19:17:32 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-06-18 19:17:32 +0900 |
| commit | c73c15cedd33c23e55965db1c335c2fa8c44f438 (patch) | |
| tree | f7e1225fdd15a5a18a8a02e52348c2324c3c8e68 | |
| parent | 84859056e05b96f0ef856dfec2a08a21342d3b95 (diff) | |
| download | caxlsx-c73c15cedd33c23e55965db1c335c2fa8c44f438.tar.gz caxlsx-c73c15cedd33c23e55965db1c335c2fa8c44f438.zip | |
properly remove invalid XML characters \u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 3 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 741e38b1..51613f75 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -541,7 +541,8 @@ module Axlsx end str.concat '</dataValidations>' end - str + '</worksheet>' + str.concat '</worksheet>' + str.tr("\u0000-\u001f\u007f\u0028", '') end # The worksheet relationships. This is managed automatically by the worksheet diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index ce2873ab..e0ea3b89 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -310,6 +310,14 @@ class TestWorksheet < Test::Unit::TestCase assert(errors.empty?, "error free validation") end + def test_to_xml_string_with_illegal_chars + nasties = "\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f" + @ws.add_row [nasties] + assert_equal(nasties, @ws.rows.last.cells.last.value) + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) + doc = Nokogiri::XML(@ws.to_xml_string) + assert(schema.validate(doc).map { |e| e.error }.empty?) + end # Make sure the XML for all optional elements (like pageMargins, autoFilter, ...) # is generated in correct order. def test_valid_with_optional_elements |
