File tree Expand file tree Collapse file tree 4 files changed +34
-12
lines changed Expand file tree Collapse file tree 4 files changed +34
-12
lines changed Original file line number Diff line number Diff line change 11# Changes
22
3+ * Gracefully handle formatting configs being set to ` nil ` instead of ` "" ` .
34* Workaround another issue caused by conflicting versions of both ` json_pure ` and ` json ` being loaded.
45
56### 2024-10-25 (2.7.4)
Original file line number Diff line number Diff line change @@ -46,15 +46,15 @@ def configure(opts)
4646 opts . each do |key , value |
4747 case key
4848 when :indent
49- self . indent = value
49+ self . indent = value || ''
5050 when :space
51- self . space = value
51+ self . space = value || ''
5252 when :space_before
53- self . space_before = value
53+ self . space_before = value || ''
5454 when :array_nl
55- self . array_nl = value
55+ self . array_nl = value || ''
5656 when :object_nl
57- self . object_nl = value
57+ self . object_nl = value || ''
5858 when :max_nesting
5959 self . max_nesting = value || 0
6060 when :depth
Original file line number Diff line number Diff line change @@ -239,13 +239,13 @@ def configure(opts)
239239 end
240240
241241 # NOTE: If adding new instance variables here, check whether #generate should check them for #generate_json
242- @indent = opts [ :indent ] if opts . key? ( :indent )
243- @space = opts [ :space ] if opts . key? ( :space )
244- @space_before = opts [ :space_before ] if opts . key? ( :space_before )
245- @object_nl = opts [ :object_nl ] if opts . key? ( :object_nl )
246- @array_nl = opts [ :array_nl ] if opts . key? ( :array_nl )
247- @allow_nan = !!opts [ :allow_nan ] if opts . key? ( :allow_nan )
248- @ascii_only = opts [ :ascii_only ] if opts . key? ( :ascii_only )
242+ @indent = opts [ :indent ] || '' if opts . key? ( :indent )
243+ @space = opts [ :space ] || '' if opts . key? ( :space )
244+ @space_before = opts [ :space_before ] || '' if opts . key? ( :space_before )
245+ @object_nl = opts [ :object_nl ] || '' if opts . key? ( :object_nl )
246+ @array_nl = opts [ :array_nl ] || '' if opts . key? ( :array_nl )
247+ @allow_nan = !!opts [ :allow_nan ] if opts . key? ( :allow_nan )
248+ @ascii_only = opts [ :ascii_only ] if opts . key? ( :ascii_only )
249249 @depth = opts [ :depth ] || 0
250250 @buffer_initial_length ||= opts [ :buffer_initial_length ]
251251
Original file line number Diff line number Diff line change @@ -167,6 +167,27 @@ def test_states
167167 assert s [ :check_circular? ]
168168 end
169169
170+ def test_falsy_state
171+ object = { foo : [ 1 , 2 ] , bar : { egg : :spam } }
172+ expected_json = JSON . generate (
173+ object ,
174+ array_nl : "" ,
175+ indent : "" ,
176+ object_nl : "" ,
177+ space : "" ,
178+ space_before : "" ,
179+ )
180+
181+ assert_equal expected_json , JSON . generate (
182+ object ,
183+ array_nl : nil ,
184+ indent : nil ,
185+ object_nl : nil ,
186+ space : nil ,
187+ space_before : nil ,
188+ )
189+ end
190+
170191 def test_pretty_state
171192 state = JSON . create_pretty_state
172193 assert_equal ( {
You can’t perform that action at this time.
0 commit comments