FIX: Invalid Unicode in preload store JSON

This commit is contained in:
Robin Ward 2013-07-02 20:43:52 -04:00
parent bb74c8b9cf
commit ce0a7739cf
2 changed files with 9 additions and 1 deletions

View file

@ -19,6 +19,14 @@ module ApplicationHelper
end
end
def escape_unicode(javascript)
if javascript
javascript.gsub(/\342\200\250/u, '&#x2028;').gsub(/(<\/)/u, '\u003C/').html_safe
else
''
end
end
def with_format(format, &block)
old_formats = formats
self.formats = [format]

View file

@ -59,7 +59,7 @@
<%- if @preloaded.present? %>
<script>
<%- @preloaded.each do |key, json| %>
PreloadStore.store("<%= key %>",<%= raw json %>);
PreloadStore.store("<%= key %>",<%= escape_unicode(json) %>);
<% end %>
</script>
<%- end %>