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

JSON emitter does not escape control characters #297

Closed
tstack opened this issue Aug 26, 2022 · 0 comments · Fixed by #298
Closed

JSON emitter does not escape control characters #297

tstack opened this issue Aug 26, 2022 · 0 comments · Fixed by #298

Comments

@tstack
Copy link

tstack commented Aug 26, 2022

The JSON emitter does not seem to be escaping control characters, like newlines. For example, with this code:

#include <stdio.h>
#include <string>
#include <ryml_all.hpp>

int main()
{

    char yml_buf[] = R"(
foo: 1
bar: [2, 3]
john: doe
comment: |
   abc
   def
)";
    ryml::Tree tree1 = ryml::parse_in_place(yml_buf);
    auto s = ryml::emitrs_json<std::string>(tree1);
    printf("%s\n", s.c_str());
}

I get this output:

{"foo": 1,"bar": [2,3],"john": "doe","comment": "abc
def
"}

The newline in the "comment" property should have been converted to a \n.

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.

1 participant