Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect UTF-32 character JSON serialization #997

Closed
nahk-ivanov opened this issue Oct 23, 2024 · 3 comments · Fixed by #998
Closed

Incorrect UTF-32 character JSON serialization #997

nahk-ivanov opened this issue Oct 23, 2024 · 3 comments · Fixed by #998

Comments

@nahk-ivanov
Copy link
Contributor

Describe the bug
When using JSON-compatible serializer (new SerializerBuilder().JsonCompatible()), it produces \Uxxxxxxxx for UTF-32 special characters (https://github.com/aaubry/YamlDotNet/blob/master/YamlDotNet/Core/Emitter.cs#L1192-L1193), which seems to be against the JSON spec, which expects two 2-byte code points instead: \uxxxx\uxxxx (also note lower-case u).

This prevents the JSON from being parsed as such by Newtonsoft.JSON library or anything else.

To Reproduce

using YamlDotNet.Serialization;

var yamlObject =
    new Deserializer().Deserialize("test:\n  - sea life \U0001F99E");

var serializer = new SerializerBuilder().JsonCompatible().Build();

Console.WriteLine(serializer.Serialize(yamlObject));

Actual:

{"test": ["sea life \U0001F99E"]}

Expected:

{"test": ["sea life \u0001\uF99E"]}
@EdwardCooke
Copy link
Collaborator

I’d have to check the yaml spec for utf 32, if there even is a spec for utf32. but that would probably be a simple change for serialiazing. Not sure about deserializing though. We do accept pr’s so if you want to submit one with applicable tests then I would be happy to merge it in. I was hoping to get a new version out last week but didn’t so I’m hoping for this weekend.

@nahk-ivanov
Copy link
Contributor Author

I think deserialization was already fixed here: #838

@nahk-ivanov
Copy link
Contributor Author

#998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@nahk-ivanov @EdwardCooke and others