aboutsummaryrefslogtreecommitdiff
path: root/lua_cjson.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* bugfix: setting encode_escape_forward_slash on a cjson instance does not ↵2.1.0.18SnowOnion2026-06-141-7/+25
| | | | affect other instances.
* bugfix: own a copy of the encode_indent stringlijunlong2026-06-071-16/+31
| | | | json_cfg_encode_indent stored the raw luaL_checkstring pointer, which aliases a Lua string that can be garbage-collected, causing a use-after-free / heap info-leak on a later encode(). Store a malloc'd copy, freed on reset and in __gc.
* optimize: rename cjson.decoce_allow_comments to cjson.decocde_allow_comment.lijunlong2026-02-101-6/+6
| | | | reslove two warnings and update the doc.
* feature: add option to allow comments in decode. skewb1k2026-02-101-5/+52
|
* feature: add option to indent encoded output.skewb1k2026-01-191-0/+56
|
* bugfix: fix truncation of decoded numbers outside lua_Integer's range (#116)or-1.29.4James McCoy2025-10-301-1/+9
| | | | | | | | | | | | json_next_number_token stores the `long long` return value from `stroll` in a `lua_Integer` (which is typically a typedef for `ptrdiff_t`). On 32-bit platforms, this ends up storing an 8-byte number into a 4-byte variable, truncating the value. Instead, store the converted value in a temporary `long long` variable so we can detect the scenario and decode into a `lua_Number`. Signed-off-by: James McCoy <jamessan@jamessan.com>
* feature: Lua 5.3 + 5.4 integer support, with CI and conflicts fixed.Hisham Muhammad2024-06-111-25/+79
| | | | | | | | | | Co-Authored-By: Hisham Muhammad <hisham@gobolinux.org> Co-authored-by: Mark Pulford <mark@kyne.com.au> Co-authored-by: ichenq <ichenq@gmail.com> Co-authored-by: Cloud Wu <cloudwu@gmail.com> Co-authored-by: caijietao <t0350.prog@gmail.com> Co-authored-by: actboy168 <actboy168@gmail.com> Co-authored-by: wudeng <wudeng256@gmail.com> Co-authored-by: caiyiheng <rangercyh@qq.com>
* bugfix: bus error or SIGSEGV caused by encode not keep buffer.hyw08102024-03-011-0/+4
|
* Bugfix: Lua cjson integer overflow issues (CVE-2022-24834) (#94)2.1.0.13lijunlong2023-07-201-3/+6
| | | | | | | * Fix integer overflows due to using wrong integer size. * Add assertions / panic when overflow still happens. Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
* feature: Add option to skip invalid value types. lijunlong2023-02-221-14/+45
| | | Co-authored-by: Jesper Lundgren <jesperlundgren@exosite.com>
* bumped version to 2.1.0.11. (#86)Johnny Wang2023-01-191-1/+1
|
* bugfix: empty_array can not work on Apple because csjon did not compare ↵Datong Sun2022-01-131-1/+1
| | | | | | | | light userdata address with masked address (#82) Since we used `json_lightudata_mask` when creating lightuserdata, same mask should be applied when comparing the return of `touserdata` Fixes #81.
* bumped version to 2.1.0.10. (#79)2.1.0.10rc12.1.0.10Johnny Wang2021-12-101-1/+1
|
* bump version to 2.1.0.92.1.0.9leaf corcoran2021-02-151-1/+1
|
* use macro instead of header defines for Lua 5.2+ supportleaf corcoran2020-04-251-4/+4
|
* support lua 5.3 with LUA_COMPAT_5_1leaf corcoran2020-04-251-0/+1
|
* support lua 5.2 with LUA_COMPAT_ALLleaf corcoran2020-04-251-0/+3
|
* feature: add option to disable forward slash escaping2.1.0.8rc12.1.0.8Jesper Lundgren2020-03-241-0/+18
| | | | Thanks @spacewander for optimization and documentation.
* bugfix: we now only apply the lightuserdata mask on platforms that are at ↵2.1.0.7rc22.1.0.7罗泽轩2018-12-071-0/+5
| | | | least 64bits.
* feature: ported to the ARM64 platform by masking off the bits higher than ↵2.1.0.7rc1spacewander2018-10-171-9/+14
| | | | | | 47-bit in the lightud. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bumped version to 2.1.0.6.2.1.0.6Yichun Zhang (agentzh)2018-04-191-1/+1
|
* optimize: improved forward-compatibility with older versions of Lua/LuaJIT.Thibault Charbonnier2018-01-021-6/+9
| | | | Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bugfix: fixed the C compiler warning "SO C90 forbids mixed declarations and ↵2.1.0.6rc2Yichun Zhang (agentzh)2017-11-171-2/+3
| | | | code" on older operating systems.
* feature: set cjson.array_mt on decoded JSON arrays.2.1.0.6rc1Thibault Charbonnier2017-11-171-0/+21
| | | | | | | this can be turned on via cjson.decode_array_with_array_mt(true). off by default. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* feature: added new cjson.array_mt metatable to allow enforcing JSON array ↵Thibault Charbonnier2017-11-151-17/+46
| | | | | | encoding. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bugfix: fixed a -Wsign-compare compiler warning.gnought2017-04-101-1/+1
| | | | Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bugfix: conditionally build luaL_setfuncs() function as the latest LuaJIT ↵2.1.0.5Datong Sun2017-04-051-2/+3
| | | | v2.1 already includes it. fixes #21.
* feature: supports MS C compiler older than VC2012.spacewander2017-01-311-0/+10
| | | | Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bugfix: preserve 'empty_array_mt' behavior upon multiple loadings of the module.Thibault Charbonnier2016-12-171-3/+14
| | | | | | | | | | | | | Prior to this fix, when the module would be loaded several times (by-passing `package.loaded`), the `lua_cjson_new` function would override the `empty_array_mt` table in the registry with a new one. Comparison for equality between those tables would then fail, and the behavior would be broken. This was discovered after loading `cjson` *and* `cjson.safe` in the same application, resulting in two calls to `lua_cjson_new`. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* bugfix: fixed compilation errors from the Microsoft C compiler.Tim Chen2016-11-061-0/+6
| | | | Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
* feat: cjson.as_array metamethod to enforce empty array encodingThibault Charbonnier2016-03-031-3/+34
| | | | | | | | | | | | | | A proposed improved patch of openresty/lua-cjson#1 (a patch commonly proposed to lua-cjson and its forks), taking into considerations comments from the original PR. - use a lightuserdata key to store the metatable in the Lua Registry (more efficient and avoiding conflicts) - provide a lightuserdata resulting in empty arrays as well - tests cases moved to t/agentzh.t, where cases for 'encode_empty_table_as_object' are already written. It seems like a better place for tests specific to the OpenResty fork's additions. - a more complex test case
* feature: now we allow up to 16 decimal places in JSON number encoding via ↵2.1.0.3Brandon2015-11-041-1/+1
| | | | | | | | cjson.encode_number_precision(). thanks lordnynex for the patch in #4. Test cases for changing precision
* feature: applied Jiale Zhi's patch to add the new config function ↵2.1.0.1Yichun Zhang (agentzh)2014-02-181-1/+13
| | | | encode_empty_table_as_object so that we can encode empty Lua tables into empty JSON arrays.
* Use Javascript compat values for Infinity/NaNMark Pulford2012-03-041-4/+12
| | | | | Use Javascript compatible values for Infinity/NaN when encoding invalid numbers.
* Bump version to 2.1develMark Pulford2012-03-041-1/+1
|
* Add cjson.safe module to suppress exceptionsMark Pulford2012-03-041-0/+58
| | | | Add cjson.safe module to suppress exceptions during JSON conversions.
* Ignore DISABLE_INVALID_NUMBERS with builtin fpconvMark Pulford2012-03-041-12/+14
|
* Bump version to 2.0develMark Pulford2012-03-041-1/+1
| | | | | Bump version to 2.0devel due to significant changes and updated API (runtime config not fully backwards compatible).
* Reserve stack slot for luaL_error() during encodeMark Pulford2012-03-041-4/+11
| | | | | | | | | | Unlike "decode", encoding leaves both the key/value on the stack before descending. This leaves no spare room for luaL_error() in case the depth check or lua_checkstack() fails. Allocate an extra stack slot to ensure there is always room for luaL_error() in json_check_encode_depth(). Note: this would not have caused a crash or fault due to the EXTRA_STACK slot reserve, but it was a misuse of the Lua C API.
* Remove deprecated "refuse_invalid_numbers"Mark Pulford2012-03-041-38/+0
| | | | | | Remove deprecated "refuse_invalid_numbers" since the version number will be bumped to 1.1.0. Also remove "version" variable since it has been replaced by _VERSION.
* Bump development version to 1.1develMark Pulford2012-03-041-1/+1
|
* Disable registration of cjson global variableMark Pulford2012-03-041-7/+2
| | | | | | | Disable registration of cjson module table global variable in the default build. Automatically creating a variable in the global namespace can cause issues for other software and is no longer recommended with Lua.
* Return boolean values from configuration functionsMark Pulford2012-03-041-5/+8
| | | | | | Return boolean values from configuration functions to simplify usage in the common case. Eg,: if not cjson.encode_invalid_numbers() then .. end
* Add depth/index to decode depth error messageMark Pulford2012-03-041-2/+3
| | | | | | | | | Include depth and character index when throwing decode nesting errors. Pre-emptively add a test decoding a massively nested JSON array. Lua stack overflow faults are unlikely to occur on simple data structures. Valgrind can highlight stack allocation bugs with complicated JSON even if the test succeeds.
* Fix Lua C function stack overflow during encodingMark Pulford2012-03-041-7/+12
| | | | | | | | | Ensure there are enough Lua stack slots available before descending into another table during encoding. This fixes a segfault when encoding deeply nested tables. This bug wasn't noticed earlier due to the previous limit of 20 nested tables.
* Simplify configuration function codeMark Pulford2012-03-041-60/+47
| | | | | | | Simplify configuration functions by adding an argument position parameter to json_enum_option() and json_integer_option(). Create json_arg_init() to check the number of arguments and return the config data.
* Merge lua_json_decode() into json_decode()Mark Pulford2012-03-041-28/+14
| | | | Also ensure cjson.decode() only receives a single argument.
* Update copyright date range to include 2012Mark Pulford2012-03-041-2/+2
|
* Change default nesting limits to 1000Mark Pulford2012-03-041-2/+2
| | | | | Increase the default nesting limits to reduce the chance of accidently throwing an error on valid JSON out of the box.
* Add option to encode invalid numbers as "null"Mark Pulford2012-03-041-65/+109
| | | | | Deprecate and replace refuse_invalid_numbers() with encode_invalid_numbers() and decode_invalid_numbers().