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

Defect in Var::parseString when there is no space between value and newline; includes fix #362

Closed
penntaylor opened this issue Jan 11, 2014 · 0 comments
Labels
Milestone

Comments

@penntaylor
Copy link

Current Poco 1.5.2-all contains a defect in Var::parseString. When the value being processed does not begin with double quotes ("), parseString treats a newline control character (\n) as part of the value rather than as a terminator. Since the JSON spec does not allow a newline control character as part of a value unless the value is a string, this is incorrect behavior.

In the example code below, the difference between the string stored in 'works' and the one stored in 'fails' is that 'works' contains a space between the 2 and the newline, while 'fails' does not. Both are valid JSON.

std::string works("{ \"a\" : 1, \"b\" : 2 \n}");
Poco::Dynamic::Var v = Poco::Dynamic::Var::parse( works );
std::cout << v.toString() << std::endl;

std::string fails("{ \"a\" : 1, \"b\" : 2\n}");
v = Poco::Dynamic::Var::parse( fails );
std::cout << v.toString() << std::endl;

Current Poco 1.5.2-all, produces this output:

{ "a" : "1", "b" : "2" }
terminate called after throwing an instance of 'Poco::DataFormatException'
  what():  Bad data format

SOLUTION: Changing line 488 of Var.cpp from

static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'

to

static const std::string OTHER_STOP("\n ,]}"); // we stop at newline, space, ',', ']' or '}'

fixes the issue, and produces the expected output:

{ "a" : "1", "b" : "2" }
{ "a" : "1", "b" : "2" }
@aleks-f aleks-f added the bug label Mar 8, 2014
@aleks-f aleks-f added this to the Release 1.5.3 milestone Mar 8, 2014
aleks-f added a commit that referenced this issue Apr 30, 2014
…tween value and newline

- fixed GH #314: JSON parsing bug
- added GH #313: MetaColumn additions for Data::ODBC and Data::SQLite
@aleks-f aleks-f closed this as completed Apr 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants