675 Commits

Author SHA1 Message Date
Jordan Bayles
5c003ecacc
Fix clang format issues (#1555) 2024-09-09 15:48:18 -07:00
Jakob Widauer
3d9bf8ee54
feat: adds front and back methods to Value type (#1458)
Value::front and Value::back
2023-06-07 12:11:01 -04:00
luzpaz
a1f1613bdd
Fix various typos (#1350)
Found via `codespell -q 3 -L alue,alse`

Co-authored-by: Christopher Dunn <cdunn2001@gmail.com>
Co-authored-by: Jordan Bayles <jophba@chromium.org>
2021-12-14 18:04:47 -08:00
Tero Kinnunen
2d55c7445f
Parse large floats as infinity (#1349) (#1353)
Return 1.9.1 functionality where values too large to fit in
double are converted to positive or negative infinity.

Commit 645cd04 changed functionality so that large floats cause
parse error, while version 1.9.1 accepted them as infinite.
This is problematic because writer outputs infinity values
as `1e+9999`, which could no longer be parsed back.

Fixed also legacy Reader even though it did not parse large values
even before breaking change, due to problematic output/parse asymmetry.

`>>` operator sets value to numeric_limits::max/lowest value if
representation is too large to fit to double. [1][2] In macos
value appears to be parsed to infinity.

> | value in *val*           | description |
> |--------------------------|-------------|
> | numeric_limits::max()    | The sequence represents a value too large for the type of val |
> | numeric_limits::lowest() | The sequence represents a value too large negative for the type of val |

[1] https://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
[2] https://www.cplusplus.com/reference/locale/num_get/get/

Signed-off-by: Tero Kinnunen <tero.kinnunen@vaisala.com>

Co-authored-by: Tero Kinnunen <tero.kinnunen@vaisala.com>
2021-12-14 18:00:28 -08:00
Francisco Javier Trujillo Mata
29f9853455 Fix cmake config for POSITION_INDEPENDENT_CODE enabling it just when BUILD_SHARED_LIBS is ON 2021-10-29 10:41:41 +02:00
Frank Dana
65bb1b1c1d
CMake: Remove ancient version checks (#1299)
The minimum version for the project is CMake 3.8.0, so there's
no point in keeping legacy code for pre-3.0 or pre-2.8 CMake.
2021-06-23 11:03:44 -07:00
Christopher Dunn
ed1ab7ac45 Avoid getline(s, EOF)
Fixes #1288
2021-05-05 01:21:22 -05:00
Billy Donahue
94cda30dbd
Rearrange Comments::set (#1278)
* slightly optimize Comments::set

Avoid allocation if the set is going to be rejected anyway.

Prototype suggestion from #1277 review thread
2021-03-18 05:22:35 -04:00
Billy Donahue
b1bd848241
fix sign-conversion warning (#1268)
Use ArrayIndex instead of int.  Fixes #1266
2021-02-20 16:07:34 -05:00
Sven Köhler
09c5ecd84f only append _static suffix for microsoft toolchains 2021-02-20 13:40:52 -06:00
Billy Donahue
fda274ddd2
Fix Value::resize to fill all array elements (#1265)
* Fix Value::resize to fill all array elements

Fixes #1264
2021-02-09 23:50:37 -05:00
GermanAizek
c9a976238b minor fixes for 64 bits and refactor code 2021-01-15 11:49:10 -05:00
Lei
940982438d
Fix a precision bug of valueToString, prevent to give an error result… (#1246)
* Fix a precision bug of valueToString, prevent to give an error result on input of wanted precision 0 and a double value which end of zero before decimal point ,such as 1230.01,12300.1;
Add test cases for double valueToString with precision 0;

* Delete a test case with platform differences in the previous commit

* Fix clang-format.

* Fix clang-format!

Co-authored-by: lilei <dlilei@126.com>
2020-12-15 11:08:05 -08:00
Marcel Opprecht
ceae0e3867
Fix clang-tidy warnings (#1231)
* Fix clang-tidy warnings

Signed-off-by: Marcel Opprecht <marcel.opprecht@scandit.com>

* Fixup/clang-format

Co-authored-by: Marcel Opprecht <marcel.opprecht@scandit.com>
Co-authored-by: Jordan Bayles <jophba@chromium.org>
2020-11-06 13:22:26 -08:00
Christopher Dunn
5d1cb30e40 clang-format 2020-10-10 11:10:09 -05:00
Ben Boeckel
c60ebf787a test: ensure the version numbers agree 2020-10-03 23:09:25 -05:00
Chen
bf0cfa5b46
hot fix for building static lib (#1203)
Fix #1197
2020-07-14 16:37:22 +08:00
Chen
cfc1ad72ad
Enhance cmake script (#1197)
* BUILD_TYPE corresponds to Release/Debug
   but LIB_TYPE corresponds to shared/static.

* Add support to build shared, static and object lib at the same time.
2020-07-13 20:33:58 +08:00
Billy Donahue
632044ad95
Billy donahue avoid isprint (#1191)
* avoid isprint

`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.

Has bitten others, e.g. https://github.com/laurikari/tre/issues/64

Fixes #1187

* semicolon (rookie mistake!)

* Windows tab escape testing with custom locale (#1190)

Co-authored-by: Nikolay Baklicharov <thestorm.nik@gmail.com>
2020-06-11 18:14:03 -04:00
Billy Donahue
b3189a0800
avoid isprint, because it is locale specific (#1189)
* avoid isprint

`std::isprint` is locale-specific and the JSON-spec is not.
In particular, isprint('\t') is true in Windows CP1252.

Has bitten others, e.g. https://github.com/laurikari/tre/issues/64

Fixes #1187

* semicolon (rookie mistake!)
2020-06-11 17:43:44 -04:00
Jordan Bayles
9be5895985
Issue 1182: Fix fuzzing bug (#1183)
This patch fixes a fuzzing bug by resolving a bad fallthrough in the
setComment logic.

The result is that we get a proper error instead of an assert, making
the library friendlier to use and less likely to cause issue for
consumers.

See related Chromium project bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=989851

Issue: 1182
2020-05-30 20:20:20 -07:00
kabeer27
6aba23f4a8
Fixes Oss-Fuzz issue: 21916 (#1180)
* Fix heap-buffer-overflow in json_reader
2020-05-29 21:50:26 +08:00
Billy Donahue
c161f4ac69
Escape control chars even if emitting UTF8 (#1178)
* Escape control chars even if emitting UTF8

See #1176
Fixes #1175

* review comments

* fix test by stopping early enough to punt on utf8-input.
2020-05-21 11:30:59 -04:00
Billy Donahue
75b360af4a
spot fix #1171: isprint argument must be representable as unsigned char (#1173) 2020-05-13 18:37:02 -04:00
Rosen Penev
e36cff19f0
clang-tidy + any_of usage (#1171)
* [clang-tidy] change functions to static

Found with readability-convert-member-functions-to-static

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* optimize JsonWriter::validate #1171

* do the same for json_reader

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* use std::any_of

Also simplified two loops.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Co-authored-by: Billy Donahue <billy.donahue@gmail.com>
2020-05-12 19:19:36 -04:00
xkszltl
a4fb5db543
Put ".exe" and ".dll" together to make test usable in build dir. (#1166) 2020-04-30 10:31:54 +08:00
Joel Johnson
3f0d63b5a9 Use internal CMake compiler version directly 2020-04-28 15:21:16 -06:00
Joel Johnson
524234e479 Use non-version checked add_compile_options
Commit aebc7fa added version checks for CMake compatibility. In reality,
only the add_compile_definitions need the check - add_compile_options
itself has been supported since 3.0. Tested and confirmed built
successfully with CMake 3.8.0.
2020-04-28 15:21:16 -06:00
Joel Johnson
30eb5ce128 Check compiler using CMAKE_CXX_COMPILER_ID
Since the introduction of CMAKE_COMPILER_IS_GNUCXX CMake has
suggested using CMAKE_CXX_COMPILER_ID for more general checks.
2020-04-28 15:21:16 -06:00
Joel Johnson
c648b0378a Consolidate setting of jsoncpp target properties 2020-04-28 15:21:16 -06:00
Joel Johnson
a3afd74b80 Don't use unique variable for postfix
The more general CMake way to handle library suffixing is to set
CMAKE_<CONFIG>_POSTFIX, so setting the Debug output suffix name should
be more correctly done by the caller or CMake configurer by setting
the desired value in CMAKE_DEBUG_POSTFIX.
2020-04-28 15:21:16 -06:00
Chen
2cb16b35dc
allowBom -> skipBom (#1162) 2020-04-28 17:30:08 +08:00
Chen
83946a28db
Ignore byte order mark in the head of UTF-8 text. (#1149)
* Ignore bom at the beginning of the UTF-8 text
2020-04-28 15:16:05 +08:00
bcsgh
91f1553f2c Make throwRuntimeError/throwLogicError print msg when built with JSON_USE_EXCEPTION=0 2020-04-24 13:40:51 -05:00
Rosen Penev
90ca694e46
clang-tidy fixes again (#1155)
* [clang-tidy] remove redundant string initialization

Found with readability-redundant-string-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] switch to raw strings

Easier to read.

Found with modernize-raw-string-literal

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] fix performance issues

Found with performance*

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* fix extra comma warnings

Found with clang's -Wextra-semi-stmt

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* remove JSONCPP_OP_EXPLICIT

This codebase in C++11. No need for compatibility with C++98.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* remove JSONCPP_NOEXCEPT

This codebase is C++11 now. No need for this macro.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 01:26:04 -04:00
Chen
3beb37ea14
revert trailing comma in old Reader (#1126) 2020-02-13 13:25:08 -08:00
Claus Klein
a6fe8e27d8
Use ccache right (#1139)
* Prevent cmakelint warnings

Use 4 spaces for indent, no tabs

* Use ccache right

fix indents too at CMakeLists.txt
2020-02-13 13:20:46 -08:00
Rosen Penev
edf528edfa
clang-tidy fixes again (#1087)
* [clang-tidy] Do not use else after return

Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] Convert several loops to be range based

Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] Replace deprecated C headers

Found with modernize-deprecated-headers

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* [clang-tidy] Use auto where applicable

Found with modernize-use-auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>

* .clang-tidy: Add these checks
2020-02-02 23:03:45 -05:00
Chen
6317f9a406
fix compile warnning using cmake (#1132) 2020-01-20 17:12:35 +08:00
Andrew Childs
f11611c878 json_writer: fix inverted sense in isAnyCharRequiredQuoting (#1120)
This bug is only affects platforms where `char` is unsigned.

When char is a signed type, values >= 0x80 are also considered < 0,
and hence require escaping due to the < ' ' condition.

When char is an unsigned type, values >= 0x80 match none of the
conditions and are considered safe to emit without escaping.

This shows up as a test failure:

* Detail of EscapeSequenceTest/writeEscapeSequence test failure:
/build/source/src/test_lib_json/main.cpp(3370): expected == result
  Expected: '["\"","\\","\b","\f","\n","\r","\t","\u0278","\ud852\udf62"]
  '
  Actual  : '["\"","\\","\b","\f","\n","\r","\t","ɸ","𤭢"]
  '
2019-12-28 15:04:24 +08:00
Chen
8f7f35c5cd
Replace Raw Unicode in Testcase (#1127)
* use unicode code point

* change values' order, because JSONTEST_ASSERT_EQUAL(expected, actual)
2019-12-26 16:08:17 +08:00
Chen
92d90250f2
fix Reader bug and add testcase (#1122) 2019-12-23 10:56:54 +08:00
Billy Donahue
d6c4a8fb2d tweak to avoid implicit narrowing warning. (#1114)
* tweak to avoid implicit narrowing warning.

change an int to size_t #1113

* Update main.cpp
2019-12-11 12:12:37 -08:00
Chen
a3c8642886
Add test cases for Reader (#1108)
* update testcase for reader

* add a helper function

* refactor structured error testing
2019-12-04 10:24:52 +08:00
Chen
2983f5a89a
Run Clang-tidy with modernize-use-auto (#1077)
* Run clang-tidy modify with modernize-use-auto
* Use using instead of typedef
2019-12-04 09:08:45 +08:00
Chen
a0bd9adfef
Add an insert overload function (#1110) 2019-12-03 09:13:42 +08:00
Billy Donahue
9e0d70aa66
eliminate some redundancy in test_lib_json/main.cpp (#1104)
refactor test 'CharReaderAllowDropNullTest/issue178'
2019-11-15 09:18:32 -05:00
dota17
f200239d5b
Add some testcases for charReader (#1095)
* update charReader test case

* remove C ++ compiler version switch for smart pointer

* remove comma test due to PR #1098
2019-11-15 14:51:43 +08:00
Jordan Bayles
9704cedb20 Issue 1100: Drop CPPTL support
CPPTL support is no longer relevant to JsonCpp, and can be removed from
the library. This patch removes all mentions of CPPTL, by removing all
definitions and code sections conditionally compiled only when JsonCpp
is used with CPPTL. Include guards are also renamed to not refer to
CPPTL where appropriate.
2019-11-14 09:38:11 -08:00
Jacob Bundgaard
1c8f7d8ae5 Run clang-format 2019-11-14 00:05:24 -06:00