Update univalue subtree
This commit is contained in:
commit
fa4d00b569
8 changed files with 23 additions and 18 deletions
|
@ -95,6 +95,7 @@ TEST_FILES = \
|
||||||
$(TEST_DATA_DIR)/fail41.json \
|
$(TEST_DATA_DIR)/fail41.json \
|
||||||
$(TEST_DATA_DIR)/fail42.json \
|
$(TEST_DATA_DIR)/fail42.json \
|
||||||
$(TEST_DATA_DIR)/fail44.json \
|
$(TEST_DATA_DIR)/fail44.json \
|
||||||
|
$(TEST_DATA_DIR)/fail45.json \
|
||||||
$(TEST_DATA_DIR)/fail3.json \
|
$(TEST_DATA_DIR)/fail3.json \
|
||||||
$(TEST_DATA_DIR)/fail4.json \
|
$(TEST_DATA_DIR)/fail4.json \
|
||||||
$(TEST_DATA_DIR)/fail5.json \
|
$(TEST_DATA_DIR)/fail5.json \
|
||||||
|
@ -105,6 +106,7 @@ TEST_FILES = \
|
||||||
$(TEST_DATA_DIR)/pass1.json \
|
$(TEST_DATA_DIR)/pass1.json \
|
||||||
$(TEST_DATA_DIR)/pass2.json \
|
$(TEST_DATA_DIR)/pass2.json \
|
||||||
$(TEST_DATA_DIR)/pass3.json \
|
$(TEST_DATA_DIR)/pass3.json \
|
||||||
|
$(TEST_DATA_DIR)/pass4.json \
|
||||||
$(TEST_DATA_DIR)/round1.json \
|
$(TEST_DATA_DIR)/round1.json \
|
||||||
$(TEST_DATA_DIR)/round2.json \
|
$(TEST_DATA_DIR)/round2.json \
|
||||||
$(TEST_DATA_DIR)/round3.json \
|
$(TEST_DATA_DIR)/round3.json \
|
||||||
|
|
|
@ -12,21 +12,10 @@ an arbitrary depth.
|
||||||
This class is aligned with the JSON standard, [RFC
|
This class is aligned with the JSON standard, [RFC
|
||||||
7159](https://tools.ietf.org/html/rfc7159.html).
|
7159](https://tools.ietf.org/html/rfc7159.html).
|
||||||
|
|
||||||
## Installation
|
## Library usage
|
||||||
|
|
||||||
This project is a standard GNU
|
This is a fork of univalue used by Bitcoin Core. It is not maintained for usage
|
||||||
[autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html)
|
by other projects. Notably, the API may break in non-backward-compatible ways.
|
||||||
project. Build and install instructions are available in the `INSTALL`
|
|
||||||
file provided with GNU autotools.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ ./autogen.sh
|
|
||||||
$ ./configure
|
|
||||||
$ make
|
|
||||||
```
|
|
||||||
|
|
||||||
## Design
|
|
||||||
|
|
||||||
UniValue provides a single dynamic RAII C++ object class,
|
|
||||||
and minimizes template use (contra json_spirit).
|
|
||||||
|
|
||||||
|
Other projects looking for a maintained library should use the upstream
|
||||||
|
univalue at https://github.com/jgarzik/univalue.
|
||||||
|
|
|
@ -47,7 +47,6 @@ public:
|
||||||
std::string s(val_);
|
std::string s(val_);
|
||||||
setStr(s);
|
setStr(s);
|
||||||
}
|
}
|
||||||
~UniValue() {}
|
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ bool ParseInt32(const std::string& str, int32_t *out)
|
||||||
errno = 0; // strtol will not set errno if valid
|
errno = 0; // strtol will not set errno if valid
|
||||||
long int n = strtol(str.c_str(), &endp, 10);
|
long int n = strtol(str.c_str(), &endp, 10);
|
||||||
if(out) *out = (int32_t)n;
|
if(out) *out = (int32_t)n;
|
||||||
// Note that strtol returns a *long int*, so even if strtol doesn't report a over/underflow
|
// Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow
|
||||||
// we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
|
// we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
|
||||||
// platforms the size of these types may be different.
|
// platforms the size of these types may be different.
|
||||||
return endp && *endp == 0 && !errno &&
|
return endp && *endp == 0 && !errno &&
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
#include "univalue.h"
|
#include "univalue.h"
|
||||||
#include "univalue_utffilter.h"
|
#include "univalue_utffilter.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* According to stackexchange, the original json test suite wanted
|
||||||
|
* to limit depth to 22. Widely-deployed PHP bails at depth 512,
|
||||||
|
* so we will follow PHP's lead, which should be more than sufficient
|
||||||
|
* (further stackexchange comments indicate depth > 32 rarely occurs).
|
||||||
|
*/
|
||||||
|
static const size_t MAX_JSON_DEPTH = 512;
|
||||||
|
|
||||||
static bool json_isdigit(int ch)
|
static bool json_isdigit(int ch)
|
||||||
{
|
{
|
||||||
return ((ch >= '0') && (ch <= '9'));
|
return ((ch >= '0') && (ch <= '9'));
|
||||||
|
@ -323,6 +331,9 @@ bool UniValue::read(const char *raw, size_t size)
|
||||||
stack.push_back(newTop);
|
stack.push_back(newTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stack.size() > MAX_JSON_DEPTH)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (utyp == VOBJ)
|
if (utyp == VOBJ)
|
||||||
setExpect(OBJ_NAME);
|
setExpect(OBJ_NAME);
|
||||||
else
|
else
|
||||||
|
|
1
src/univalue/test/fail45.json
Normal file
1
src/univalue/test/fail45.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
|
@ -114,6 +114,7 @@ static const char *filenames[] = {
|
||||||
"fail41.json", // invalid unicode: unfinished UTF-8
|
"fail41.json", // invalid unicode: unfinished UTF-8
|
||||||
"fail42.json", // valid json with garbage following a nul byte
|
"fail42.json", // valid json with garbage following a nul byte
|
||||||
"fail44.json", // unterminated string
|
"fail44.json", // unterminated string
|
||||||
|
"fail45.json", // nested beyond max depth
|
||||||
"fail3.json",
|
"fail3.json",
|
||||||
"fail4.json", // extra comma
|
"fail4.json", // extra comma
|
||||||
"fail5.json",
|
"fail5.json",
|
||||||
|
@ -124,6 +125,7 @@ static const char *filenames[] = {
|
||||||
"pass1.json",
|
"pass1.json",
|
||||||
"pass2.json",
|
"pass2.json",
|
||||||
"pass3.json",
|
"pass3.json",
|
||||||
|
"pass4.json",
|
||||||
"round1.json", // round-trip test
|
"round1.json", // round-trip test
|
||||||
"round2.json", // unicode
|
"round2.json", // unicode
|
||||||
"round3.json", // bare string
|
"round3.json", // bare string
|
||||||
|
|
Loading…
Add table
Reference in a new issue