You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	#126 fix space in case map key is sorted
This commit is contained in:
		| @@ -101,9 +101,10 @@ func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||||
| 			stream.WriteMore() | ||||
| 		} | ||||
| 		encodeMapKey(key, stream) | ||||
| 		stream.writeByte(':') | ||||
| 		if stream.indention > 0 { | ||||
| 			stream.writeByte(' ') | ||||
| 			stream.writeTwoBytes(byte(':'), byte(' ')) | ||||
| 		} else { | ||||
| 			stream.writeByte(':') | ||||
| 		} | ||||
| 		val := realVal.MapIndex(key).Interface() | ||||
| 		encoder.elemEncoder.EncodeInterface(val, stream) | ||||
| @@ -185,7 +186,11 @@ func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||||
| 			stream.WriteMore() | ||||
| 		} | ||||
| 		stream.WriteVal(key.s) // might need html escape, so can not WriteString directly | ||||
| 		stream.writeByte(':') | ||||
| 		if stream.indention > 0 { | ||||
| 			stream.writeTwoBytes(byte(':'), byte(' ')) | ||||
| 		} else { | ||||
| 			stream.writeByte(':') | ||||
| 		} | ||||
| 		val := realVal.MapIndex(key.v).Interface() | ||||
| 		encoder.elemEncoder.EncodeInterface(val, stream) | ||||
| 	} | ||||
|   | ||||
| @@ -78,4 +78,7 @@ func Test_marshal_indent_map(t *testing.T) { | ||||
| 	output, err = MarshalIndent(obj, "", "  ") | ||||
| 	should.Nil(err) | ||||
| 	should.Equal("{\n  \"1\": 2\n}", string(output)) | ||||
| 	output, err = ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", "  ") | ||||
| 	should.Nil(err) | ||||
| 	should.Equal("{\n  \"1\": 2\n}", string(output)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user