You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	#153 fix invalid utf8 using same implementation as the standard library
This commit is contained in:
		| @@ -286,8 +286,11 @@ func writeStringSlowPathWithHTMLEscaped(stream *Stream, i int, s string, valLen | ||||
| 		} | ||||
| 		c, size := utf8.DecodeRuneInString(s[i:]) | ||||
| 		if c == utf8.RuneError && size == 1 { | ||||
| 			if start < i { | ||||
| 				stream.WriteRaw(s[start:i]) | ||||
| 			} | ||||
| 			stream.WriteRaw(`\ufffd`) | ||||
| 			i++ | ||||
| 			stream.WriteRaw(s[start:i]) | ||||
| 			start = i | ||||
| 			continue | ||||
| 		} | ||||
|   | ||||
| @@ -122,8 +122,11 @@ func Test_invalid_number(t *testing.T) { | ||||
| 	obj := Message{} | ||||
| 	decoder := ConfigCompatibleWithStandardLibrary.NewDecoder(bytes.NewBufferString(`{"number":"5"}`)) | ||||
| 	err := decoder.Decode(&obj) | ||||
| 	result, err := ConfigCompatibleWithStandardLibrary.Marshal(err.Error()) | ||||
| 	invalidStr := err.Error() | ||||
| 	result, err := ConfigCompatibleWithStandardLibrary.Marshal(invalidStr) | ||||
| 	should := require.New(t) | ||||
| 	should.Nil(err) | ||||
| 	should.Contains(string(result), "\xff") | ||||
| 	result2, err := json.Marshal(invalidStr) | ||||
| 	should.Nil(err) | ||||
| 	should.Equal(string(result2), string(result)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user