@@ -46,6 +46,8 @@ class << self
46
46
def encode ( value , options = nil )
47
47
if options . nil? || options . empty?
48
48
Encoding . encode_without_options ( value )
49
+ elsif options == { escape : false } . freeze
50
+ Encoding . encode_without_escape ( value )
49
51
else
50
52
Encoding . json_encoder . new ( options ) . encode ( value )
51
53
end
@@ -164,7 +166,14 @@ class JSONGemCoderEncoder # :nodoc:
164
166
165
167
166
168
def initialize ( options = nil )
167
- @options = options ? options . dup . freeze : { } . freeze
169
+ if options
170
+ options = options . dup
171
+ @escape = options . delete ( :escape ) { true }
172
+ @options = options . freeze
173
+ else
174
+ @escape = true
175
+ @options = { } . freeze
176
+ end
168
177
end
169
178
170
179
# Encode the given object into a JSON string
@@ -173,7 +182,7 @@ def encode(value)
173
182
174
183
json = CODER . dump ( value )
175
184
176
- return json unless @options . fetch ( : escape, true )
185
+ return json unless @escape
177
186
178
187
# Rails does more escaping than the JSON gem natively does (we
179
188
# escape \u2028 and \u2029 and optionally >, <, & to work around
@@ -209,11 +218,16 @@ class << self
209
218
def json_encoder = ( encoder )
210
219
@json_encoder = encoder
211
220
@encoder_without_options = encoder . new
221
+ @encoder_without_escape = encoder . new ( escape : false )
212
222
end
213
223
214
224
def encode_without_options ( value ) # :nodoc:
215
225
@encoder_without_options . encode ( value )
216
226
end
227
+
228
+ def encode_without_escape ( value ) # :nodoc:
229
+ @encoder_without_escape . encode ( value )
230
+ end
217
231
end
218
232
219
233
self . use_standard_json_time_format = true
0 commit comments