From af1c2d1f5692f925a6dfd51cf2cb7d25a1ece0f6 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sat, 17 Aug 2013 14:44:43 +0900 Subject: Extracted control char sanitization to module level and applied to shared strings table output. --- lib/axlsx.rb | 8 ++++++++ lib/axlsx/workbook/shared_strings_table.rb | 1 + lib/axlsx/workbook/worksheet/worksheet.rb | 10 +--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 8cecf47a..ffebc7ac 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -127,6 +127,14 @@ module Axlsx s.gsub(/_(.)/){ $1.upcase } end + # returns the provided string with all invalid control charaters + # removed. + # @param [String] str The sting to process + # @return [String] + def self.sanitize(str) + str.gsub(CONTROL_CHAR_REGEX, '') + end + # Instructs the serializer to not try to escape cell value input. # This will give you a huge speed bonus, but if you content has <, > or other xml character data diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb index 7c08205e..ed6643f2 100644 --- a/lib/axlsx/workbook/shared_strings_table.rb +++ b/lib/axlsx/workbook/shared_strings_table.rb @@ -50,6 +50,7 @@ module Axlsx str << '' << @shared_xml_string << '' + str = Axlsx::sanitize(str) end private diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index ecba9254..df755abf 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -552,15 +552,7 @@ module Axlsx item.to_xml_string(str) if item end str << '' - sanitize(str) - end - - # returns the provided string with all invalid control charaters - # removed. - # @param [String] str The sting to process - # @return [String] - def sanitize(str) - str.gsub(CONTROL_CHAR_REGEX, '') + Axlsx::sanitize(str) end # The worksheet relationships. This is managed automatically by the worksheet -- cgit v1.2.3