Skip to content

Commit 721de4b

Browse files
committed
Merge branch 'master' (1.4.1) into v0.8.z (0.8.1)
2 parents b31d224 + e7233bf commit 721de4b

File tree

7 files changed

+176
-43
lines changed

7 files changed

+176
-43
lines changed

README.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ pairs.
77

88
[json-org]: http://json.org/
99

10-
JsonCpp is a C++ library that allows manipulating JSON values, including
10+
[JsonCpp][] is a C++ library that allows manipulating JSON values, including
1111
serialization and deserialization to and from strings. It can also preserve
1212
existing comment in unserialization/serialization steps, making it a convenient
1313
format to store user input files.
1414

15+
[JsonCpp]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
16+
1517
## A note on backward-compatibility
16-
Very soon, we are switching to C++11 only. For older compilers, try the `pre-C++11` branch.
18+
* `1.y.z` is built with C++11.
19+
* `0.8.z` can be used with older compilers.
20+
* Major versions maintain binary-compatibility.
1721

1822
Using JsonCpp in your project
1923
-----------------------------
20-
2124
The recommended approach to integrating JsonCpp in your project is to build
2225
the amalgamated source (a single `.cpp` file) with your own build system. This
2326
ensures consistency of compilation flags and ABI compatibility. See the section
@@ -28,13 +31,11 @@ should be included as follow:
2831

2932
#include <json/json.h>
3033

31-
If JsonCpp was build as a dynamic library on Windows, then your project needs to
34+
If JsonCpp was built as a dynamic library on Windows, then your project needs to
3235
define the macro `JSON_DLL`.
3336

34-
35-
Building and testing with new CMake
36-
-----------------------------------
37-
37+
Building and testing with CMake
38+
-------------------------------
3839
[CMake][] is a C++ Makefiles/Solution generator. It is usually available on most
3940
Linux system as package. On Ubuntu:
4041

@@ -75,10 +76,8 @@ the `-G` option).
7576
By default CMake hides compilation commands. This can be modified by specifying
7677
`-DCMAKE_VERBOSE_MAKEFILE=true` when generating makefiles.
7778

78-
7979
Building and testing with SCons
8080
-------------------------------
81-
8281
**Note:** The SCons-based build system is deprecated. Please use CMake; see the
8382
section above.
8483

@@ -107,14 +106,7 @@ If you are building with Microsoft Visual Studio 2008, you need to set up the
107106
environment by running `vcvars32.bat` (e.g. MSVC 2008 command prompt) before
108107
running SCons.
109108

110-
111-
Running the tests manually
112-
--------------------------
113-
114-
Note that test can be run using SCons using the `check` target:
115-
116-
scons platform=$PLATFORM check
117-
109+
# Running the tests manually
118110
You need to run tests manually only if you are troubleshooting an issue.
119111

120112
In the instructions below, replace `path/to/jsontest` with the path of the
@@ -137,20 +129,21 @@ In the instructions below, replace `path/to/jsontest` with the path of the
137129
# You can run the tests using valgrind:
138130
python rununittests.py --valgrind path/to/test_lib_json
139131

132+
## Running the tests using scons
133+
Note that tests can be run using SCons using the `check` target:
134+
135+
scons platform=$PLATFORM check
140136

141137
Building the documentation
142138
--------------------------
143-
144139
Run the Python script `doxybuild.py` from the top directory:
145140

146141
python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
147142

148143
See `doxybuild.py --help` for options.
149144

150-
151145
Generating amalgamated source and header
152146
----------------------------------------
153-
154147
JsonCpp is provided with a script to generate a single header and a single
155148
source file to ease inclusion into an existing project. The amalgamated source
156149
can be generated at any time by running the following command from the
@@ -172,10 +165,8 @@ The amalgamated sources are generated by concatenating JsonCpp source in the
172165
correct order and defining the macro `JSON_IS_AMALGAMATION` to prevent inclusion
173166
of other headers.
174167

175-
176168
Adding a reader/writer test
177169
---------------------------
178-
179170
To add a test, you need to create two files in test/data:
180171

181172
* a `TESTNAME.json` file, that contains the input document in JSON format.
@@ -195,10 +186,8 @@ The `TESTNAME.expected` file format is as follows:
195186
See the examples `test_complex_01.json` and `test_complex_01.expected` to better
196187
understand element paths.
197188

198-
199189
Understanding reader/writer test output
200190
---------------------------------------
201-
202191
When a test is run, output files are generated beside the input test files.
203192
Below is a short description of the content of each file:
204193

@@ -215,10 +204,7 @@ Below is a short description of the content of each file:
215204
* `test_complex_01.process-output`: `jsontest` output, typically useful for
216205
understanding parsing errors.
217206

218-
219207
License
220208
-------
221-
222209
See the `LICENSE` file for details. In summary, JsonCpp is licensed under the
223210
MIT license, or public domain if desired and recognized in your jurisdiction.
224-

doc/jsoncpp.dox

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,24 @@ std::cin >> root;
5656
// You can also read into a particular sub-value.
5757
std::cin >> root["subtree"];
5858

59-
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
60-
// such member.
59+
// Get the value of the member of root named 'encoding',
60+
// and return 'UTF-8' if there is no such member.
6161
std::string encoding = root.get("encoding", "UTF-8" ).asString();
62-
// Get the value of the member of root named 'encoding'; return a 'null' value if
62+
63+
// Get the value of the member of root named 'plug-ins'; return a 'null' value if
6364
// there is no such member.
6465
const Json::Value plugins = root["plug-ins"];
65-
for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
66+
67+
// Iterate over the sequence elements.
68+
for ( int index = 0; index < plugins.size(); ++index )
6669
loadPlugIn( plugins[index].asString() );
6770

71+
// Try other datatypes. Some are auto-convertible to others.
6872
foo::setIndentLength( root["indent"].get("length", 3).asInt() );
6973
foo::setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
7074

71-
// Since Json::Value has implicit constructor for all value types, it is not
72-
// necessary to explicitly construct the Json::Value object:
75+
// Since Json::Value has an implicit constructor for all value types, it is not
76+
// necessary to explicitly construct the Json::Value object.
7377
root["encoding"] = foo::getCurrentEncoding();
7478
root["indent"]["length"] = foo::getCurrentIndentLength();
7579
root["indent"]["use_space"] = foo::getCurrentIndentUseSpace();
@@ -152,6 +156,7 @@ Basically JsonCpp is licensed under MIT license, or public domain if desired
152156
and recognized in your jurisdiction.
153157

154158
\author Baptiste Lepilleur <[email protected]> (originator)
159+
\author Christopher Dunn <[email protected]> (primary maintainer)
155160
\version \include version
156161
We make strong guarantees about binary-compatibility, consistent with
157162
<a href="http://apr.apache.org/versioning.html">the Apache versioning scheme</a>.

include/json/reader.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,26 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
254254
/** Configuration of this builder.
255255
These are case-sensitive.
256256
Available settings (case-sensitive):
257-
- "collectComments": false or true
257+
- `"collectComments": false or true`
258258
- true to collect comment and allow writing them
259259
back during serialization, false to discard comments.
260260
This parameter is ignored if allowComments is false.
261-
- "allowComments": false or true
261+
- `"allowComments": false or true`
262262
- true if comments are allowed.
263-
- "strictRoot": false or true
263+
- `"strictRoot": false or true`
264264
- true if root must be either an array or an object value
265-
- "allowDroppedNullPlaceholders": false or true
265+
- `"allowDroppedNullPlaceholders": false or true`
266266
- true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
267-
- "allowNumericKeys": false or true
267+
- `"allowNumericKeys": false or true`
268268
- true if numeric object keys are allowed.
269-
- "stackLimit": integer
269+
- `"stackLimit": integer`
270+
- Exceeding stackLimit (recursive depth of `readValue()`) will
271+
cause an exception.
270272
- This is a security issue (seg-faults caused by deeply nested JSON),
271273
so the default is low.
274+
- `"failIfExtra": false or true`
275+
- If true, `parse()` returns false when extra non-whitespace trails
276+
the JSON value in the input string.
272277
273278
You can examine 'settings_` yourself
274279
to see the defaults. You can also write and read them just like any

include/json/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#ifndef JSON_VERSION_H_INCLUDED
55
# define JSON_VERSION_H_INCLUDED
66

7-
# define JSONCPP_VERSION_STRING "0.8.0"
7+
# define JSONCPP_VERSION_STRING "0.8.1"
88
# define JSONCPP_VERSION_MAJOR 0
99
# define JSONCPP_VERSION_MINOR 8
10-
# define JSONCPP_VERSION_PATCH 0
10+
# define JSONCPP_VERSION_PATCH 1
1111
# define JSONCPP_VERSION_QUALIFIER
1212
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
1313

src/lib_json/json_reader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ class OurFeatures {
826826
bool strictRoot_;
827827
bool allowDroppedNullPlaceholders_;
828828
bool allowNumericKeys_;
829+
bool failIfExtra_;
829830
int stackLimit_;
830831
}; // OurFeatures
831832

@@ -991,6 +992,12 @@ bool OurReader::parse(const char* beginDoc,
991992
bool successful = readValue();
992993
Token token;
993994
skipCommentTokens(token);
995+
if (features_.failIfExtra_) {
996+
if (token.type_ != tokenError && token.type_ != tokenEndOfStream) {
997+
addError("Extra non-whitespace after JSON value.", token);
998+
return false;
999+
}
1000+
}
9941001
if (collectComments_ && !commentsBefore_.empty())
9951002
root.setComment(commentsBefore_, commentAfter);
9961003
if (features_.strictRoot_) {
@@ -1704,6 +1711,7 @@ CharReader* CharReaderBuilder::newCharReader() const
17041711
features.allowDroppedNullPlaceholders_ = settings_["allowDroppedNullPlaceholders"].asBool();
17051712
features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
17061713
features.stackLimit_ = settings_["stackLimit"].asInt();
1714+
features.failIfExtra_ = settings_["failIfExtra"].asBool();
17071715
return new OurCharReader(collectComments, features);
17081716
}
17091717
static void getValidReaderKeys(std::set<std::string>* valid_keys)
@@ -1715,6 +1723,7 @@ static void getValidReaderKeys(std::set<std::string>* valid_keys)
17151723
valid_keys->insert("allowDroppedNullPlaceholders");
17161724
valid_keys->insert("allowNumericKeys");
17171725
valid_keys->insert("stackLimit");
1726+
valid_keys->insert("failIfExtra");
17181727
}
17191728
bool CharReaderBuilder::validate(Json::Value* invalid) const
17201729
{
@@ -1742,6 +1751,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings)
17421751
(*settings)["strictRoot"] = true;
17431752
(*settings)["allowDroppedNullPlaceholders"] = false;
17441753
(*settings)["allowNumericKeys"] = false;
1754+
(*settings)["failIfExtra"] = true;
17451755
//! [CharReaderBuilderStrictMode]
17461756
}
17471757
// static
@@ -1754,6 +1764,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
17541764
(*settings)["allowDroppedNullPlaceholders"] = false;
17551765
(*settings)["allowNumericKeys"] = false;
17561766
(*settings)["stackLimit"] = 1000;
1767+
(*settings)["failIfExtra"] = false;
17571768
//! [CharReaderBuilderDefaults]
17581769
}
17591770

0 commit comments

Comments
 (0)