diff options
| author | Randy Morgan <[email protected]> | 2013-08-17 14:44:43 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2013-08-17 14:44:43 +0900 |
| commit | af1c2d1f5692f925a6dfd51cf2cb7d25a1ece0f6 (patch) | |
| tree | 74d077a0b423e76b8115dc6bf38e8e85af9db075 | |
| parent | 7bd3f1fa3837f0387ac18f5caaac89d1986592a8 (diff) | |
| download | caxlsx-af1c2d1f5692f925a6dfd51cf2cb7d25a1ece0f6.tar.gz caxlsx-af1c2d1f5692f925a6dfd51cf2cb7d25a1ece0f6.zip | |
Extracted control char sanitization to module level and applied to shared strings table output.
| -rw-r--r-- | lib/axlsx.rb | 8 | ||||
| -rw-r--r-- | lib/axlsx/workbook/shared_strings_table.rb | 1 | ||||
| -rw-r--r-- | 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 << '<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '"' str << ' count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '"' str << ' xml:space="' << xml_space.to_s << '">' << @shared_xml_string << '</sst>' + 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 << '</worksheet>' - 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 |
