petehug / wjelement-cpp

WJElement-cpp - Lightweight C++ wrapper for WJElement with JSON Schema support
GNU Lesser General Public License v3.0
9 stars 3 forks source link

String fields and escaping #4

Open sinukus opened 8 years ago

sinukus commented 8 years ago

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 commented 8 years ago

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:notifications@github.com] Sent: Thursday, 5 November 2015 9:08 a.m. To: petehug/wjelement-cpp wjelement-cpp@noreply.github.com 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 https://github.com/petehug/wjelement-cpp/issues/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 commented 8 years ago

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