diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-06-12 09:13:55 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-06-12 09:15:26 +0200 |
commit | ebab5d3c59558000f0e0fd18b7f26ed6f31ac21a (patch) | |
tree | bd10fac5e8064c51fddb32d4dfc6e1ad26a576c7 | |
parent | dd8fe8215a59c0885dd7df43ef8e245544bcab82 (diff) | |
parent | 0cc7b2352e749a7863d7b5ed680e3fb5f04f9511 (diff) |
Merge pull request #6266
0cc7b23 Fix univalue handling of \u0000 characters. (Daniel Kraft)
-rw-r--r-- | src/test/univalue_tests.cpp | 6 | ||||
-rw-r--r-- | src/univalue/univalue_read.cpp | 15 |
2 files changed, 10 insertions, 11 deletions
diff --git a/src/test/univalue_tests.cpp b/src/test/univalue_tests.cpp index de84faca23..2c1d303f66 100644 --- a/src/test/univalue_tests.cpp +++ b/src/test/univalue_tests.cpp @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(univalue_object) } static const char *json1 = -"[1.10000000,{\"key1\":\"str\",\"key2\":800,\"key3\":{\"name\":\"martian\"}}]"; +"[1.10000000,{\"key1\":\"str\\u0000\",\"key2\":800,\"key3\":{\"name\":\"martian\"}}]"; BOOST_AUTO_TEST_CASE(univalue_readwrite) { @@ -306,7 +306,9 @@ BOOST_AUTO_TEST_CASE(univalue_readwrite) BOOST_CHECK_EQUAL(obj.size(), 3); BOOST_CHECK(obj["key1"].isStr()); - BOOST_CHECK_EQUAL(obj["key1"].getValStr(), "str"); + std::string correctValue("str"); + correctValue.push_back('\0'); + BOOST_CHECK_EQUAL(obj["key1"].getValStr(), correctValue); BOOST_CHECK(obj["key2"].isNum()); BOOST_CHECK_EQUAL(obj["key2"].getValStr(), "800"); BOOST_CHECK(obj["key3"].isObject()); diff --git a/src/univalue/univalue_read.cpp b/src/univalue/univalue_read.cpp index 5cea778996..261771811d 100644 --- a/src/univalue/univalue_read.cpp +++ b/src/univalue/univalue_read.cpp @@ -188,25 +188,22 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed, case 't': valStr += "\t"; break; case 'u': { - char buf[4] = {0,0,0,0}; - char *last = &buf[0]; unsigned int codepoint; if (hatoui(raw + 1, raw + 1 + 4, codepoint) != raw + 1 + 4) return JTOK_ERR; if (codepoint <= 0x7f) - *last = (char)codepoint; + valStr.push_back((char)codepoint); else if (codepoint <= 0x7FF) { - *last++ = (char)(0xC0 | (codepoint >> 6)); - *last = (char)(0x80 | (codepoint & 0x3F)); + valStr.push_back((char)(0xC0 | (codepoint >> 6))); + valStr.push_back((char)(0x80 | (codepoint & 0x3F))); } else if (codepoint <= 0xFFFF) { - *last++ = (char)(0xE0 | (codepoint >> 12)); - *last++ = (char)(0x80 | ((codepoint >> 6) & 0x3F)); - *last = (char)(0x80 | (codepoint & 0x3F)); + valStr.push_back((char)(0xE0 | (codepoint >> 12))); + valStr.push_back((char)(0x80 | ((codepoint >> 6) & 0x3F))); + valStr.push_back((char)(0x80 | (codepoint & 0x3F))); } - valStr += buf; raw += 4; break; } |