Sha256: 73271608058899cf89e14e165bb4f7929f738a5eef6785c30985b78b5315bf02
Contents?: true
Size: 681 Bytes
Versions: 12
Compression:
Stored size: 681 Bytes
Contents
module Unpoly module Rails class Util class << self def json_decode(string) ActiveSupport::JSON.decode(string) end # We build a lot of JSON that goes into HTTP header. # High-ascii characters are not safe to transport over HTTP, but we # can use JSON escape sequences (\u0012) to make them low-ascii. def safe_json_encode(value) json = ActiveSupport::JSON.encode(value) escape_non_ascii(json) end def escape_non_ascii(unicode_string) unicode_string.gsub(/[[:^ascii:]]/) { |char| "\\u" + char.ord.to_s(16).rjust(4, "0") } end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems