-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Utf8YamlEmitter.BeginScalar | Scalar tags are not written when the CurrentState is BlockMappingValue #97
Comments
I found another instance of this issue in the Tags are not written before scalar values in flow sequences. Proposed Solution |
Tag emitter support is very limited and, as you point out, incomplete. First, I only supported tagging to BlockMapping to support Union. If possible, could you please share some sample code that shows unintended behaviour? |
Here's a sample with each of the issues above. There is also one additional issue where block sequence elements are written out of the sequence if a tag is set before the element. Utf8YamlEmitter emitter = new(writer);
emitter.BeginMapping();
{
emitter.WriteString("A1");
emitter.Tag("!a1");
emitter.WriteFloat(float.Pi); // !a1 is skipped and written later
emitter.WriteString("NoTag1");
emitter.BeginSequence(SequenceStyle.Flow); // !a1 is written here instead of after A1:
{
emitter.Tag("!a2"); // This tag is ignored unless the sequence style is Block
emitter.WriteString("A2");
}
emitter.EndSequence();
emitter.WriteString("NoTag2");
emitter.BeginSequence(SequenceStyle.Block); // !a2 is not written here like it was for !a1 (because of the SequenceStyle)
{
emitter.Tag("!a3"); // This tag is written, but it breaks the sequence
emitter.WriteString("A3"); // This is written outside of the sequence
}
emitter.EndSequence();
}
emitter.EndMapping(); Here is the real output: A1: 3.1415927
NoTag1: !a1 [A2]
NoTag2:
- !a3
A3 This is the desired output: A1: !a1 3.1415927
NoTag1: [!a2 A2]
NoTag2:
- !a3 A3 Please let me know if you need anything else. Thanks for your amazing work on this library. |
Thanks! I'm working on #98. |
Merged #98 . Thanks a lot. |
The Issue
When emitting a simple YAML struct, I noticed my tags were written (prefixed) before the wrong values. When writing any value scalar the tag is not written, but the tag is written the next time a Sequence is written.
Looking into it further, I found out that the
CurrentState
when writing the scalar values wasEmitState.BlockMappingValue
, which skips writing the tag. See Utf8YamlEmitter.BeginScalar >Is there a reason
EmitState.BlockMappingValue
does not write the current tag whenEmitState.FlowMappingValue
andEmitState.None
do?I am new to the codebase so I might be doing something wrong, but it seems odd.
Proposed Solution
Include
EmitState.BlockMappingValue
in the case withEmitState.FlowMappingValue
andEmitState.None
so the tag is written.If this should not be done, I would appreciate some pointers on how this should be correctly handled.
Note
If it's easier, I'd be happy to make a PR.
The text was updated successfully, but these errors were encountered: