Incorrect string length passed to yaml_document_add_scalar() in __YAMLSerializationAddObject()
TheGS opened this issue · comments
In __YAMLSerializationAddObject(), there is a call to yaml_document_add_scalar() with a pointer to the UTF8 form of the NSString, but the number of Unicode characters is used as the byte length of that UTF8 string. This will definitely be incorrect if the string has any characters that require more than 1 byte to represent in UTF8. In any case, since -[NSString UTF8String] returns a C string, it's sufficient to use a value of -1... code in yaml_document_add_scalar() will detect this and call strlen() on the C string to get the correct string length.
Absolutely
YAML.framework/YAMLSerialization.m
Line 255 in c099c4b
[string lengthOfBytesUsingEncoding: NSUTF8StringEncoding]
which may be bit faster.