Skip to content

Commit

Permalink
Extracted control char sanitization to module level and applied to sh…
Browse files Browse the repository at this point in the history
…ared strings table output.

Conflicts:
	lib/axlsx/workbook/shared_strings_table.rb
  • Loading branch information
randym authored and tcannonfodder committed Aug 15, 2014
1 parent 077a9d5 commit f8ef8eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lib/axlsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def self.camel(s="", all_caps = true)
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
Expand Down
3 changes: 2 additions & 1 deletion lib/axlsx/workbook/shared_strings_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def initialize(cells)
# @param [String] str
# @return [String]
def to_xml_string
'<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '" count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '">' << @shared_xml_string << '</sst>'
str = '<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '" count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '">' << @shared_xml_string << '</sst>'
str = Axlsx::sanitize(str)
end

private
Expand Down
10 changes: 1 addition & 9 deletions lib/axlsx/workbook/worksheet/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,7 @@ def to_xml_string
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
Expand Down

0 comments on commit f8ef8eb

Please sign in to comment.