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

String fields and escaping #4

Open
sinukus opened this issue Nov 4, 2015 · 2 comments
Open

String fields and escaping #4

sinukus opened this issue Nov 4, 2015 · 2 comments

Comments

@sinukus
Copy link

sinukus commented Nov 4, 2015

Hi,
The addString call doesn't appear to provide and JSON escaping.

e.g. if I do
std::string fileTag("File");
std::string fileName("File");
node.setString(fileTag, fileName);
then I call dump I'll get:
{
"file":"c:\foo"
}

which is invalid JSON.

I noticed that WJWriteString does escaping, but that doesn't seem to be called by dump or setString.

Is it expected that the clients must hand the library properly escaped JSON strings or is this a bug, or is dump not the right way to extract the JSON?

@petehug
Copy link
Owner

petehug commented Nov 5, 2015

Thank you for pointing this out!

I fixed the issue and also added output stream insertion methods for Node objects so that you can send a node to a stream in the normal way:

std::cout << node << std::endl;

This will not be pretty printed so is the ideal way to create json files not intended for human consumtion.

You can continue to use the dump() method if you want pretty printed output.

Please pull an update from github.

From: sinukus [mailto:[email protected]]
Sent: Thursday, 5 November 2015 9:08 a.m.
To: petehug/wjelement-cpp [email protected]
Subject: [wjelement-cpp] String fields and escaping (#4)

Hi,
The addString call doesn't appear to provide and JSON escaping.

e.g. if I do
std::string fileTag("File");
std::string fileName("File");
node.setString(fileTag, fileName);
then I call dump I'll get:
{
"file":"c:\foo"
}

which is invalid JSON.

I noticed that WJWriteString does escaping, but that doesn't seem to be called by dump or setString.

Is it expected that the clients must hand the library properly escaped JSON strings or is this a bug, or is dump not the right way to extract the JSON?


Reply to this email directly or view it on GitHub #4 . https://github.com/notifications/beacon/AAn3qsnbkUc1aDEd8W5OH1USpLeSgkWzks5pCl08gaJpZM4GcDZG.gif


This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

@sinukus
Copy link
Author

sinukus commented Nov 5, 2015

great, thanks! I'll check out your fix!

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

No branches or pull requests

2 participants