-
Hi, Project: Name: test_project_file_7ed30cb41d Nodes: - File: Nodes/test_project_file_7ed30cb41d.yaml Attached is the file: test_project_file_7ed30cb41d.txt The offending chars are: f3 a0 81 93 (after the Nodes: ) My question is does the parser detect non printable characters like these? Thanks EDIT : here is the MVE: #include <iostream>
#include <iomanip>
#include <cstdlib>
#include "ryml_std.hpp"
#include "c4/yml/tree.hpp"
#include "c4/yml/parse.hpp"
using namespace c4::yml;
void ErrorCallback(char const* message, size_t, Location, void*)
{
std::cout << "ErrorCallback:" << message << std::endl;
}
std::string GetStringFrom(c4::csubstr const& nodeValue)
{
std::string result;
from_chars(nodeValue, &result);
return result;
}
int main(int argc, char* argv[])
{
Callbacks callbacks(nullptr, nullptr, nullptr, ErrorCallback);
set_callbacks(callbacks);
const char yml_buf[] = u8"Project:\n Name: test_project_file_7ed30cb41d\n Nodes:\n - xF3xA0x81x93File: Nodes/test_project_file_7ed30cb41d.yaml";
Tree tree = parse(yml_buf);
if (tree.empty())
std::cout << "parse failed" << std::endl;
NodeRef projectNode = tree["Project"];
NodeRef nodes = projectNode["Nodes"];
for (auto const& node : nodes.children())
{
auto const fileNode = node["File"]; // Error callback is called when in debug. but not in release
auto const value = fileNode.val();
std::cout << "value=" << value <<std::endl;
GetStringFrom(value);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
EDIT: @winneymj Now that an MVE is present, the problem is clear. The crash occurs because you're trying to get the value on a non-existing node. It is up to you to check whether the node exists, but Debug builds help you detect the problem. The special characters come not after In short, if you use --- original answer: Non-printable characters are ignored unless they surround YAML block style markup (ie As for the crash you refer, I am not clear on what exactly is the problem. It would help if you provide a MVE in C++ code that shows the problem. I'm having trouble looking at the hex file. If you can show the file encoded as a string, it will make it easier for me to pinpoint what's going on. |
Beta Was this translation helpful? Give feedback.
-
Hi,
You asked "is the YAML invalid?" A good question. My assumption was no as
they are non-printable characters, but I am not a YAML expert and if the
YAML specification allows for non-printable chars after a - then it would
be valid.
Please elaborate. What is a MVE? I assume a virtual environment of
some sort?
…On Fri, Sep 2, 2022 at 12:10 PM jpmag ***@***.***> wrote:
RYML_ASSERT() works just like assert() (and can be enabled/disabled with
use of NDEBUG, and further with RYML_USE_ASSERT). It is an internal
development tool to verify assumptions and preconditions. It will incur a
significant runtime cost. Also, it is not meant to verify integrity of the
data. A parse error is a different thing, and should always result in a
call to the error callback; if it doesn't it is a bug, and should be
reported.
In your case, the YAML parse was successful, and it is only after this
phase, when you're going through the data, that the assertion fires because
you are accessing a non-existent element. So trying to work around the
problem by enabling/disabling assertions is not addressing the root cause:
is the YAML invalid? From what I saw in the file, it looks like the YAML is
valid, but it's hard for me to be sure because the bytes you mentioned are
not occurring after Nodes: , but after - , where they become valid and
end up as part of the scalar.
If you want concrete help, please provide a MVE here as a C++ snippet (not
a VS project, I am using linux and I can't open that project.)
—
Reply to this email directly, view it on GitHub
<#300 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABK26BAFGDPYZEFHIK7CFZLV4IYIXANCNFSM6AAAAAAQCXRRYI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
To me it looks like the character isn't a non-printable one, but https://www.compart.com/en/unicode/U+E0053 "Tag Latin Capital Letter S" |
Beta Was this translation helpful? Give feedback.
EDIT: @winneymj Now that an MVE is present, the problem is clear. The crash occurs because you're trying to get the value on a non-existing node. It is up to you to check whether the node exists, but Debug builds help you detect the problem.
The special characters come not after
Nodes:
(as originally described) but on the seq opened after it, ie afterNodes:\n -
. So the- File:
that you assume to be there is actually- xF3xA0x81x93File:
, and thusnode
has no member with keyFile
; it isxF3xA0x81x93File
instead. That's why you cannot getnode["File"].val()
:node["File"]
does not exist unless you create it (is a seed node, it is not valid, and only if you write to it via=
or<<
will it …