lib/extended_fields_helpers.rb
module ExtendedFieldsHelpers
unless included_modules.include? ExtendedFieldsHelpers
# move any problematic punctuation that will mess up our xml
# element name to html entities
# currently for \,/,&,',",comma,<,>
# allowed: .,_,-
# should handle the case where & is a part of an entity already
# and not escape it
def encode_problematic_punctuation_to_entities(string)
string.to_s.gsub(/&(?![\#\d\w]+;)/, '&').gsub(/\"/, '"').gsub(/>/, '>').gsub(/</, '<').gsub(/\'/, ''').gsub(/\//, '/').gsub(/\\/, '\').gsub(/,/, ',')
end
def decode_problematic_punctuation_to_entities(string)
string.to_s.gsub(/"/, '"').gsub(/>/, '>').gsub(/</, '<').gsub(/'/, "\'").gsub(///, '/').gsub(/\/, '\\').gsub(/,/, ',').gsub(/&/, '&')
end
end
end