mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[1626] check string termination and whitespace fix
whitespace 'outside' of elements is skipped, now including \r and \b
This commit is contained in:
@@ -354,6 +354,9 @@ str_from_stringstream(std::istream &in, const std::string& file, const int line,
|
|||||||
c = in.get();
|
c = in.get();
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
if (c == EOF) {
|
||||||
|
throwJSONError("Unterminated string", file, line, pos);
|
||||||
|
}
|
||||||
return (ss.str());
|
return (ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,7 +461,7 @@ from_stringstream_list(std::istream &in, const std::string& file, int& line,
|
|||||||
ElementPtr list = Element::createList();
|
ElementPtr list = Element::createList();
|
||||||
ConstElementPtr cur_list_element;
|
ConstElementPtr cur_list_element;
|
||||||
|
|
||||||
skip_chars(in, " \t\n", line, pos);
|
skip_chars(in, " \t\n\r\b", line, pos);
|
||||||
while (c != EOF && c != ']') {
|
while (c != EOF && c != ']') {
|
||||||
if (in.peek() != ']') {
|
if (in.peek() != ']') {
|
||||||
cur_list_element = Element::fromJSON(in, file, line, pos);
|
cur_list_element = Element::fromJSON(in, file, line, pos);
|
||||||
@@ -476,7 +479,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
|
|||||||
int& pos)
|
int& pos)
|
||||||
{
|
{
|
||||||
ElementPtr map = Element::createMap();
|
ElementPtr map = Element::createMap();
|
||||||
skip_chars(in, " \t\n", line, pos);
|
skip_chars(in, " \t\n\r\b", line, pos);
|
||||||
char c = in.peek();
|
char c = in.peek();
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
throwJSONError(std::string("Unterminated map, <string> or } expected"), file, line, pos);
|
throwJSONError(std::string("Unterminated map, <string> or } expected"), file, line, pos);
|
||||||
@@ -574,7 +577,7 @@ Element::fromJSON(std::istream &in, const std::string& file, int& line,
|
|||||||
char c = 0;
|
char c = 0;
|
||||||
ElementPtr element;
|
ElementPtr element;
|
||||||
bool el_read = false;
|
bool el_read = false;
|
||||||
skip_chars(in, " \n\t", line, pos);
|
skip_chars(in, " \n\t\r\b", line, pos);
|
||||||
while (c != EOF && !el_read) {
|
while (c != EOF && !el_read) {
|
||||||
c = in.get();
|
c = in.get();
|
||||||
pos++;
|
pos++;
|
||||||
|
@@ -338,7 +338,11 @@ TEST(Element, escape) {
|
|||||||
// Bad string
|
// Bad string
|
||||||
EXPECT_THROW(Element::fromJSON("hello\"foobar\""), JSONError);
|
EXPECT_THROW(Element::fromJSON("hello\"foobar\""), JSONError);
|
||||||
// A whitespace test
|
// A whitespace test
|
||||||
EXPECT_NO_THROW(Element::fromJSON(" \n \r \t \n \n \t"));
|
EXPECT_NO_THROW(Element::fromJSON("\" \n \r \t \n \n \t\""));
|
||||||
|
// Whitespace outside of json element
|
||||||
|
EXPECT_NO_THROW(Element::fromJSON(" \n \t \r \b \"\" \n \t \r \b"));
|
||||||
|
EXPECT_NO_THROW(Element::fromJSON("{ \n \r \t \b }"));
|
||||||
|
EXPECT_NO_THROW(Element::fromJSON("[ \n \r \t \b ]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Element, ListElement) {
|
TEST(Element, ListElement) {
|
||||||
|
Reference in New Issue
Block a user