summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNoel Peden <[email protected]>2021-02-12 09:23:19 -0800
committerGitHub <[email protected]>2021-02-12 09:23:19 -0800
commit7790a5f8e0bc8e41cec132c04c99df04e6412aa8 (patch)
treed783ca0770465818dbc6d53d169bcc00ab68311e
parentcda1ce451db1c0754f1e102e1d809467c79a6d8f (diff)
parentfb7b437a2c75075c6ff99e441a0cf22428b2ebdc (diff)
downloadcaxlsx-7790a5f8e0bc8e41cec132c04c99df04e6412aa8.tar.gz
caxlsx-7790a5f8e0bc8e41cec132c04c99df04e6412aa8.zip
Merge pull request #78 from rfdonnelly/fix-special-char-in-pivot-cache-def
Fix special characters in pivot table cache definition
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb2
-rw-r--r--test/workbook/worksheet/tc_pivot_table_cache_definition.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
index f136b663..969b0bf2 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
@@ -53,7 +53,7 @@ module Axlsx
str << '</cacheSource>'
str << ( '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">')
pivot_table.header_cells.each do |cell|
- str << ( '<cacheField name="' << cell.value << '" numFmtId="0">')
+ str << ( '<cacheField name="' << cell.clean_value << '" numFmtId="0">')
str << '<sharedItems count="0">'
str << '</sharedItems>'
str << '</cacheField>'
diff --git a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
index 282078b0..37d7e485 100644
--- a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
+++ b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
@@ -51,4 +51,12 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase
assert(errors.empty?, "error free validation")
end
+ def test_to_xml_string_for_special_characters
+ cell = @ws.rows.first.cells.first
+ cell.value = "&><'\""
+
+ doc = Nokogiri::XML(@cache_definition.to_xml_string)
+ errors = doc.errors
+ assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+ end
end