Skip to content

Commit

Permalink
informative text why do we replace \u2028 and \u2029
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed May 9, 2016
1 parent 28e95ea commit de43789
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ def server_rendered_react_component_html(props, react_component_name, dom_id,
ReactOnRails::ServerRenderingPool.reset_pool_if_server_bundle_was_modified

# Since this code is not inserted on a web page, we don't need to escape props
#
# However, as JSON (returned from `props_string(props)`) isn't JavaScript,
# but we want treat it as such, we need to compensate for the difference.
#
# \u2028 and \u2029 are valid characters in strings in JSON, but are treated
# as newline separators in JavaScript. As no newlines are allowed in
# strings in JavaScript, this causes an exception.
#
# We fix this by replacing these unicode characters with their escaped versions.
# This should be safe, as the only place they can appear is in strings anyway.
#
# Read more here: http://timelessrepo.com/json-isnt-a-javascript-subset

wrapper_js = <<-JS
(function() {
Expand Down

0 comments on commit de43789

Please sign in to comment.