@@ -545,43 +545,41 @@ public IRubyObject _configure(ThreadContext context, IRubyObject vOpts) {
545545 checkFrozen ();
546546 OptionsReader opts = new OptionsReader (context , vOpts );
547547
548- ByteList indent = opts .getString ("indent" );
549- if (indent != null ) this .indent = indent ;
550-
551- ByteList space = opts .getString ("space" );
552- if (space != null ) this .space = space ;
553-
554- ByteList spaceBefore = opts .getString ("space_before" );
555- if (spaceBefore != null ) this .spaceBefore = spaceBefore ;
556-
557- ByteList arrayNl = opts .getString ("array_nl" );
558- if (arrayNl != null ) this .arrayNl = arrayNl ;
559-
560- this .asJSON = opts .getProc ("as_json" );
561-
562- ByteList objectNl = opts .getString ("object_nl" );
563- if (objectNl != null ) this .objectNl = objectNl ;
564-
565- maxNesting = opts .getInt ("max_nesting" , DEFAULT_MAX_NESTING );
566- allowNaN = opts .getBool ("allow_nan" , DEFAULT_ALLOW_NAN );
567- asciiOnly = opts .getBool ("ascii_only" , DEFAULT_ASCII_ONLY );
568- scriptSafe = opts .getBool ("script_safe" , DEFAULT_SCRIPT_SAFE );
569- strict = opts .getBool ("strict" , DEFAULT_STRICT );
570- bufferInitialLength = opts .getInt ("buffer_initial_length" , DEFAULT_BUFFER_INITIAL_LENGTH );
571-
572- depth = opts .getInt ("depth" , 0 );
548+ this .indent = stringConfig (opts , "indent" , this .indent );
549+ this .space = stringConfig (opts , "space" , this .space );
550+ this .spaceBefore = stringConfig (opts , "space_before" , this .spaceBefore );
551+ this .arrayNl = stringConfig (opts , "array_nl" , this .arrayNl );
552+ this .objectNl = stringConfig (opts , "object_nl" , this .objectNl );
553+
554+ if (opts .hasKey ("as_json" )) this .asJSON = opts .getProc ("as_json" );
555+
556+ maxNesting = opts .getInt ("max_nesting" , maxNesting );
557+ allowNaN = opts .getBool ("allow_nan" , allowNaN );
558+ asciiOnly = opts .getBool ("ascii_only" , asciiOnly );
559+ scriptSafe = opts .getBool ("script_safe" , scriptSafe );
560+ strict = opts .getBool ("strict" , strict );
561+ bufferInitialLength = opts .getInt ("buffer_initial_length" , bufferInitialLength );
562+
563+ depth = opts .getInt ("depth" , depth );
573564 if (depth < 0 ) {
574565 throw context .runtime .newArgumentError ("depth must be >= 0 (got: " + depth + ")" );
575566 }
576- this .allowDuplicateKey = opts .getBool ("allow_duplicate_key" , false );
567+ this .allowDuplicateKey = opts .getBool ("allow_duplicate_key" , allowDuplicateKey );
577568
578- sortKeys = normalizeSortKeys (context , opts .get ("sort_keys" ));
569+ if ( opts . hasKey ( "sort_keys" )) sortKeys = normalizeSortKeys (context , opts .get ("sort_keys" ));
579570
580571 opts .ensureEmpty ();
581572
582573 return this ;
583574 }
584575
576+ // A falsy value writes the empty string, as string_config() does in the C extension.
577+ private static ByteList stringConfig (OptionsReader opts , String key , ByteList current ) {
578+ if (!opts .hasKey (key )) return current ;
579+ ByteList value = opts .getString (key );
580+ return value == null ? ByteList .EMPTY_BYTELIST : value ;
581+ }
582+
585583 /**
586584 * <code>State#to_h()</code>
587585 *
0 commit comments