Fix bug on tags starting with "!!"#1427
Conversation
|
@adfhkjafsdk Very cool! Could you add some tests? |
|
@SGSSGene Thanks for your appreciation! I added some tests for SetTag. I also noticed that we lack test for emitting SecondaryTag, added to test/integration/emitter_test.cpp. After adding the test, it occurred to me that EmitFromEvents::EmitProps has problems handling named tag handles, like By the way, I'm not sure what the expected output is for codes like this: YAML::Node node;
node = 42;
node.SetTag("!a!");
YAML::Node root;
root["num"] = node;
YAML::Emitter out;
std::cout << out.c_str() << std::endl;Currently I left it |
There was a problem hiding this comment.
@adfhkjafsdk Thank you so much. Good to see progress on these issues!
You are using 'tabs' instead of spaces in the source code. Please change it to spaces.
About the 'Named handles'.
If I read the specs correctly a tag !a! is not allowed, because it has a non-empty suffix (!a!b would be fine).
See 6.9.1 Node Tags specifically the Tag shorthands.
The example in Example 6.27 Invalid Tag Shorthands even shows this as invalid.
So I think the right thing to do is throw an exception for invalid tag.
Secondly, currently we do not really have support for named tags at all.
Strictly speaking even !a!b would be invalid if !a! wasn't specified before.
The currently master implementation just handles this case wrongly which might be very surprising for library users.
I think it would be much nice to also throw an exception with some thing like "!TODO: Unsupported named tag". And maybe in that code section a comment to this PR so the next person knows where we left off.
@jbeder: do you have any insights to the TAG support of yaml-cpp?
fix style glitch Co-authored-by: Simon Gene Gottlieb <simon@gottliebtfreitag.de>
fix style glitch Co-authored-by: Simon Gene Gottlieb <simon@gottliebtfreitag.de>
|
@SGSSGene Thank you for your hard work. I feel sorry about the poor indentation. I totally agree with the idea of throwing an exception for invalid tag. I wonder why the old implementation just ignore the invalid tag I know that Currently there's no By the way I felt it inconvenient to store tag as a raw string ( |
To me the same happens, because of the difference between 2 vs 4 space indentation.
I believe this is something only @jbeder can tell us. I wouldn't be surprised if this just wasn't focus and is just open to do.
I agree, there wouldn't be any way of emitting a shorthand tags (currently it is also not possible). I would argue
Another good question, maybe @jbeder has some insights here?
This is something I would need to look into and can't comment on :-) |
Fixes #1373 .
This adds support for SecondaryTag in EmitFromEvents::EmitProps, resolving tags starting with "!!".
Now the output of the example code is