diff -Nru lua-json-1.3.3/debian/changelog lua-json-1.3.4/debian/changelog --- lua-json-1.3.3/debian/changelog 2016-12-29 14:34:34.000000000 +0000 +++ lua-json-1.3.4/debian/changelog 2019-02-02 18:45:38.000000000 +0000 @@ -1,3 +1,20 @@ +lua-json (1.3.4-2) unstable; urgency=medium + + * [06f652f] Migrating the git repo to salsa + * [899d394] Add .gitlab-ci.yml + + -- Bernd Zeimetz Sat, 02 Feb 2019 19:45:38 +0100 + +lua-json (1.3.4-1) unstable; urgency=medium + + * [f162566] Update upstream source from tag 'upstream/1.3.4' + Update to upstream version '1.3.4' + with Debian dir 547a6d91bf0c18b7a75a52cd2bc97e82436f1360 + * [27f7046] snapshot changelog + * [a2ed30d] README was renamed to README.md + + -- Bernd Zeimetz Sat, 02 Feb 2019 19:03:36 +0100 + lua-json (1.3.3-2) unstable; urgency=medium * [59e7e01] Support lua5.3. diff -Nru lua-json-1.3.3/debian/control lua-json-1.3.4/debian/control --- lua-json-1.3.3/debian/control 2016-12-29 14:34:34.000000000 +0000 +++ lua-json-1.3.4/debian/control 2019-02-02 18:45:38.000000000 +0000 @@ -4,8 +4,8 @@ Maintainer: Bernd Zeimetz Build-Depends: debhelper (>= 8), dh-lua (>= 21) Standards-Version: 3.9.6 -Vcs-Git: git://git.bzed.at/debian/pkg-liblua-json.git -Vcs-Browser: https://git.bzed.at/summary/debian%2Fpkg-liblua-json.git +Vcs-Git: https://salsa.debian.org/debian/liblua-json.git +Vcs-Browser: https://salsa.debian.org/debian/liblua-json Homepage: http://www.eharning.us/wiki/luajson/ Package: lua-json diff -Nru lua-json-1.3.3/debian/.gitlab-ci.yml lua-json-1.3.4/debian/.gitlab-ci.yml --- lua-json-1.3.3/debian/.gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/debian/.gitlab-ci.yml 2019-02-02 18:45:38.000000000 +0000 @@ -0,0 +1,11 @@ +image: registry.salsa.debian.org/salsa-ci-team/ci-image-git-buildpackage:latest + +pages: + stage: deploy + artifacts: + paths: + - public + script: + - gitlab-ci-git-buildpackage + - gitlab-ci-lintian + - gitlab-ci-aptly diff -Nru lua-json-1.3.3/debian/lua-json.docs lua-json-1.3.4/debian/lua-json.docs --- lua-json-1.3.3/debian/lua-json.docs 2016-12-29 14:34:34.000000000 +0000 +++ lua-json-1.3.4/debian/lua-json.docs 2019-02-02 18:45:38.000000000 +0000 @@ -1,2 +1,3 @@ docs/* -README +README.md + diff -Nru lua-json-1.3.3/docs/LuaJSON.txt lua-json-1.3.4/docs/LuaJSON.txt --- lua-json-1.3.3/docs/LuaJSON.txt 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/docs/LuaJSON.txt 2017-02-01 04:44:11.000000000 +0000 @@ -112,7 +112,14 @@ unicodeWhitespace : boolean:: Specifies if unicode whitespace characters are counted -array.trailingComma / object.trailingComma : boolean:: +array.allowEmptyElement / calls.allowEmptyElement / object.allowEmptyElement : boolean:: + Specifies if missing values are allowed, replacing them with the value of 'undefined' or 'null' if undefined not allowed. + Example cases: + [1,, 3] ==> { 1, json.util.undefined, 3 } + { x: } ==> { x = json.util.undefined } + call(1,, 3) ==> call(1, json.util.undefined, 3) + +array.trailingComma / calls.trailingComma / object.trailingComma : boolean:: Specifies if extraneous trailing commas are ignored in declaration calls.defs : map:: diff -Nru lua-json-1.3.3/docs/ReleaseNotes-1.3.4.txt lua-json-1.3.4/docs/ReleaseNotes-1.3.4.txt --- lua-json-1.3.3/docs/ReleaseNotes-1.3.4.txt 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/docs/ReleaseNotes-1.3.4.txt 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,103 @@ +luajson v1.3.4 Release Notes +============================ + +User Visible Changes +-------------------- + +Maintenance for older versions (ex: 1.0.x, 1.1.x, 1.2.x) will be on-demand. No +longer will changes be introduced there and trickled down. + +The main changes for this release are: + + * Lua 5.3 and LuaJIT 2.1-beta support added. + * LPEG 1.0.1 support verified. + * Documentation enhancements: + * README converted to MarkDown. + * Address utility method documentation to address exposed + public-use methods. + * Address utility method documentation to call out unsupported + internal methods. + * Address GitHub issue #38: + * A new allowEmptyElement option is available that will make + array and map building more forgiving for missing entries. + +Plans for next release +---------------------- +At this point there are no particular strong plans for next release. + +Enhancing error output and performance are goals, but not terribly high on my +priority list. + + +Updates since 1.3.3 +=================== + +Thomas Harning Jr (65): + base: + drops obsolute SCM rockspecs + updates lunit tests to pass through interpreter + adds travis-ci build file + fixes travis + travis fixes - drop unsupported Lua5.2 lpeg versions and add missing make build + fixes regression test lua path + travis fixes - drop unsupported Lua5.2 lpeg versions and add missing make build + applies required branch list to travis + rewrite language as python for broader support of the .travis.yml + updates Travis-CI build structure to use sample + lua is always symlinked as the correct version + expands to newer versions of Lua/luajit + switch to lunitx due to expanded Lua 5.2, Lua 5.3 support + build: + reverses build order to assign greater importance to newer items + updates to LPEG 0.12.2 due to Lua5.3 compat patch + adds LPeg 1.0.0 and trims a build from 0.12.2 tree + ci: + updates travis.yml to allow feature branches + update used version of LuaRocks + replaces LPEG 1.0.0 testing with 1.0.1 testing + codecov: + apply report generation automatically + compat: + fixes unpack calls to lookup table.unpack before the 5.2-deprecated/removed unpack + decode+docs+tests: + adds support for (array/object/calls).allowEmptyElement to address GH #38 + decode.calls+tests: + handle trailingCommas in own setting vs borrowing 'array' configuration + decode.strings+tests: + fixes additionalEscapes to override builtin escapes and side-step escapeCheck needing to be altered + decoder: + drops unused 'expected' utility method + docs: + updates README to indicate updated testing results and drops mention of travis-ci pieces due to removal + cleans up reference for non-present functionality GH #37 and adds details for json.util + updates README to reflect new test LPEG platform and Lua 5.3.4 release + encode: + simplify encoder map building to current use case to enhance coverage + license: + updates copyright year + luacov: + update path to point to right location + not using luacov-coveralls + test: + update tests to not rely removed math.pow + update utf-8 handler to be more strict about integer division + tests: + updates to Lua 5.2/5.3 requirements + updates more strongly to Lua 5.2/5.3 requirements by dropping _M usage + adds positive test case with nothrow to enhance test coverage + adds multiple registered calls and nested calls to enhance test coverage + enhances coverage for number parsing options + enhances coverage for strings.additionalEscapes decoding option + enhances coverage for NaN handling + enhances coverage for undefined and unregistered method encoding + travis: + synchronizes with moteus/lua-travis-example to fix LuaJIT builds + use hererocks for local install management + adds in coveralls coverage reporting + run coveralls in verbose mode + try global coveralls support + manually do codecov generation after transforming to relative paths + attempt downgrading luacov to 0.9.1 to fix line stats +Ewan Breakey (1): + -ungrouped- + Update README to use MarkDown diff -Nru lua-json-1.3.3/LICENSE lua-json-1.3.4/LICENSE --- lua-json-1.3.3/LICENSE 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/LICENSE 2017-02-01 04:44:11.000000000 +0000 @@ -5,7 +5,7 @@ The MIT License -Copyright (c) 2008-2014 Thomas Harning Jr. +Copyright (c) 2008-2017 Thomas Harning Jr. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff -Nru lua-json-1.3.3/lua/json/decode/composite.lua lua-json-1.3.4/lua/json/decode/composite.lua --- lua-json-1.3.3/lua/json/decode/composite.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json/decode/composite.lua 2017-02-01 04:44:11.000000000 +0000 @@ -22,18 +22,22 @@ local defaultOptions = { array = { + allowEmptyElement = false, trailingComma = true }, object = { + allowEmptyElement = false, trailingComma = true, number = true, identifier = true, setObjectKey = rawset }, calls = { + allowEmptyElement = false, defs = nil, -- By default, do not allow undefined calls to be de-serialized as call objects - allowUndefined = false + allowUndefined = false, + trailingComma = true } } diff -Nru lua-json-1.3.3/lua/json/decode/state.lua lua-json-1.3.4/lua/json/decode/state.lua --- lua-json-1.3.3/lua/json/decode/state.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json/decode/state.lua 2017-02-01 04:44:11.000000000 +0000 @@ -8,7 +8,7 @@ local assert = assert local type = type local next = next -local unpack = unpack +local unpack = require("table").unpack or unpack local _ENV = nil @@ -49,23 +49,37 @@ end end assert(self.active_key, "Missing key value") - object_options.setObjectKey(self.active, self.active_key, self:grab_value()) + object_options.setObjectKey(self.active, self.active_key, self:grab_value(object_options.allowEmptyElement)) self.active_key = nil end function state_ops.put_array_value(self, trailing) + local array_options = self.options.array -- Safety check - if trailing and not self.previous_set and self.options.array.trailingComma then + if trailing and not self.previous_set and array_options.trailingComma then return end local new_index = self.active_state + 1 self.active_state = new_index - self.active[new_index] = self:grab_value() + self.active[new_index] = self:grab_value(array_options.allowEmptyElement) +end + +function state_ops.put_call_value(self, trailing) + local call_options = self.options.calls + -- Safety check + if trailing and not self.previous_set and call_options.trailingComma then + return + end + local new_index = self.active_state + 1 + self.active_state = new_index + self.active[new_index] = self:grab_value(call_options.allowEmptyElement) end function state_ops.put_value(self, trailing) if self.active_state == 'object' then self:put_object_value(trailing) + elseif self.active.func then + self:put_call_value(trailing) else self:put_array_value(trailing) end @@ -102,7 +116,7 @@ end function state_ops.end_object(self) - if self.previous_set or next(self.active) then + if self.active_key or self.previous_set or next(self.active) then -- Not an empty object self:put_value(true) end @@ -141,7 +155,11 @@ self.previous = nil end -function state_ops.grab_value(self) +function state_ops.grab_value(self, allowEmptyValue) + if not self.previous_set and allowEmptyValue then + -- Calculate an appropriate empty-value + return self.emptyValue + end assert(self.previous_set, "Previous value not set") self.previous_set = false return self.previous @@ -167,6 +185,13 @@ local function create(options) + local emptyValue + -- Calculate an empty value up front + if options.others.allowUndefined then + emptyValue = options.others.undefined or nil + else + emptyValue = options.others.null or nil + end local ret = { options = options, stack = {}, @@ -176,8 +201,8 @@ active = nil, active_key = nil, previous = nil, - active_state = nil - + active_state = nil, + emptyValue = emptyValue } return setmetatable(ret, state_mt) end diff -Nru lua-json-1.3.3/lua/json/decode/strings.lua lua-json-1.3.4/lua/json/decode/strings.lua --- lua-json-1.3.3/lua/json/decode/strings.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json/decode/strings.lua 2017-02-01 04:44:11.000000000 +0000 @@ -107,12 +107,12 @@ local escapeMatch = doSimpleSub escapeMatch = escapeMatch + doXSub / decodeX escapeMatch = escapeMatch + doUniSub / options.decodeUnicode - if options.additionalEscapes then - escapeMatch = escapeMatch + options.additionalEscapes - end if options.escapeCheck then escapeMatch = options.escapeCheck * escapeMatch + bad_escape end + if options.additionalEscapes then + escapeMatch = options.additionalEscapes + escapeMatch + end local captureString for i = 1, #quotes do local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch) diff -Nru lua-json-1.3.3/lua/json/decode/util.lua lua-json-1.3.4/lua/json/decode/util.lua --- lua-json-1.3.3/lua/json/decode/util.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json/decode/util.lua 2017-02-01 04:44:11.000000000 +0000 @@ -39,16 +39,6 @@ local msg = "unexpected character" return build_report(msg) end -local function expected(...) - local items = {...} - local msg - if #items > 1 then - msg = "expected one of '" .. table_concat(items, "','") .. "'" - else - msg = "expected '" .. items[1] .. "'" - end - return build_report(msg) -end local function denied(item, option) local msg if option then @@ -113,7 +103,6 @@ local util = { unexpected = unexpected, - expected = expected, denied = denied, ascii_space = ascii_space, unicode_space = unicode_space, diff -Nru lua-json-1.3.3/lua/json/encode.lua lua-json-1.3.4/lua/json/encode.lua --- lua-json-1.3.3/lua/json/encode.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json/encode.lua 2017-02-01 04:44:11.000000000 +0000 @@ -53,17 +53,12 @@ loadedModules[name] = mod end --- Merges values, assumes all tables are arrays, inner values flattened, optionally constructing output -local function flattenOutput(out, values) - out = not out and {} or type(out) == 'table' and out or {out} - if type(values) == 'table' then - for _, v in ipairs(values) do - out[#out + 1] = v - end - else - out[#out + 1] = values - end - return out +-- NOTE: Nested not found, so assume unsupported until use case arises +local function flattenOutput(out, value) + assert(type(value) ~= 'table') + out = out or {} + out[#out + 1] = value + return out end -- Prepares the encoding map from the already provided modules and new config diff -Nru lua-json-1.3.3/lua/json.lua lua-json-1.3.4/lua/json.lua --- lua-json-1.3.3/lua/json.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/lua/json.lua 2017-02-01 04:44:11.000000000 +0000 @@ -13,7 +13,7 @@ local json = { _VERSION = "1.3.4", _DESCRIPTION = "LuaJSON : customizable JSON decoder/encoder", - _COPYRIGHT = "Copyright (c) 2007-2014 Thomas Harning Jr. ", + _COPYRIGHT = "Copyright (c) 2007-2017 Thomas Harning Jr. ", decode = decode, encode = encode, util = util diff -Nru lua-json-1.3.3/Makefile lua-json-1.3.4/Makefile --- lua-json-1.3.3/Makefile 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/Makefile 2017-02-01 04:44:11.000000000 +0000 @@ -32,7 +32,7 @@ check-regression: cd tests && $(LUA_SETUP) $(LUA_BIN) regressionTest.lua check-unit: - cd tests && $(LUA_SETUP) $(LUNIT_BIN) lunit-*.lua + cd tests && $(LUA_SETUP) $(LUNIT_BIN) --interpreter $(LUA_BIN) lunit-*.lua check: check-regression check-unit diff -Nru lua-json-1.3.3/README lua-json-1.3.4/README --- lua-json-1.3.3/README 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/README 1970-01-01 00:00:00.000000000 +0000 @@ -1,69 +0,0 @@ -LuaJSON - JSON Parser/Constructor for Lua - -Author: Thomas Harning Jr. - -Source code: - http://repo.or.cz/luajson - -Bug reports: - http://github.com/harningt/luajson - harningt@gmail.com - -Requirements - Lua 5.1, 5.2, or LuaJIT 2.0 - LPeg (Tested with 0.7, 0.8, 0.9, 0.10, 0.12rc2 ... 0.6 mostly works) - For regressionTest: - lfs (Tested with 1.4.1) - For lunit-tests: - lunit >= 0.4 - -NOTE: LPeg 0.11 may not work - it crashed during my tests - -Lua versions tested recently: - Lua 5.1.4 + strict + pl.strict - Lua 5.2.0 + pl.strict - LuaJIT-2.0.0-beta10 + strict + pl.strict - -License - All-but tests: MIT-style, See LICENSE for details - tests/*: Public Domain / MIT - whichever is least restrictive - -Module/Function overview: - json.encode (callable module referencing json.encode.encode) - --encode ( value : ANY-valid ) - - Takes in a JSON-encodable value and returns the JSON-encoded text - Valid input types: - table - array-like table (spec below) - string - number - boolean - 'null' - represented by json.util.null - Table keys (string,number,boolean) are encoded as strings, others are erroneus - Table values are any valid input-type - Array-like tables are converted into JSON arrays... - Position 1 maps to JSON Array position 0 - --isEncodable ( value : ANY ) - Returns a boolean stating whether is is encodeable or not - NOTE: Tables/arrays are not deeply inspected - - json.decode (callable module referencing json.decode.decode) - --decode (data : string, strict : optional boolean) - Takes in a string of JSON data and converts it into a Lua object - If 'strict' is set, then the strict JSON rule-set is used - - json.util - --printValue (tab : ANY, name : string) - recursively prints out all object values - if duplicates found, reference printed - --null - Reference value to represent 'null' in a well-defined way to - allow for null values to be inserted into an array/table - --merge (t : table, ... : tables) - Shallow-merges a sequence of tables onto table t by iterating over each using - pairs and assigning. - -Attribution: - parsing test suite from JSON_checker project of http://www.json.org/ - No listed license for these files in their package. diff -Nru lua-json-1.3.3/README.md lua-json-1.3.4/README.md --- lua-json-1.3.3/README.md 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/README.md 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,115 @@ +## LuaJSON +JSON Parser/Constructor for Lua + +### Author: +Thomas Harning Jr. + +### Source code: +http://repo.or.cz/luajson + +### Bug reports: +http://github.com/harningt/luajson +harningt@gmail.com + +### Requirements +Lua 5.1, 5.2, 5.3, LuaJIT 2.0, or LuaJIT 2.1 +LPeg (Tested with 0.7, 0.8, 0.9, 0.10, 0.12rc2, 1.0.1) +For regressionTest: + lfs (Tested with 1.6.3) +### For lunit-tests: +lunitx >= 0.8 + +### NOTE: +LPeg 0.11 may not work - it crashed during my initial tests, +it is not in the test matrix. + +### Lua versions tested recently: +* Lua 5.1.5 +* Lua 5.2.4 +* Lua 5.3.4 +* LuaJIT-2.0.4 +* LuaJIT-2.1.0-beta2 + +### License +All-but tests: MIT-style, See LICENSE for details +tests/*: Public Domain / MIT - whichever is least restrictive + +### Module/Function overview: +### json.encode (callable module referencing json.encode.encode) +___encode ( value : ANY-valid )___ + +Takes in a JSON-encodable value and returns the JSON-encoded text +Valid input types: +* table +* array-like table (spec below) +* string +* number +* boolean +* 'null' - represented by json.util.null + +Table keys (string,number,boolean) are encoded as strings, others are erroneus +Table values are any valid input-type +Array-like tables are converted into JSON arrays... +Position 1 maps to JSON Array position 0 + +### json.decode (callable module referencing json.decode.decode) +___decode (data : string, strict : optional boolean)___ + +Takes in a string of JSON data and converts it into a Lua object +If 'strict' is set, then the strict JSON rule-set is used + +### json.util +#### Useful utilities +___null___ + +Reference value to represent 'null' in a well-defined way to +allow for null values to be inserted into an array/table + + undefined + +Reference value to represent 'undefined' in a well-defined +way to allow for undefined values to be inserted into an +array/table. + + IsArray (t : ANY) + +Checks if the passed in object is a plain-old-array based on +whether or not is has the LuaJSON array metatable attached +or the custom __is_luajson_array metadata key stored. + + InitArray(t: table) + +Sets the 'array' marker metatable to guarantee the table is +represented as a LuaJSON array type. + + isCall (t : ANY) + +Checks if the passed in object is a LuaJSON call object. + + buildCall(name : string, ... parameters) + +Builds a call object with the given name and set of parameters. +The name is stored in the 'name' field and the parameters in +the 'parameters' field as an array. + +#### Additional Utilities + clone (t : table) + +Shallow-clones a table by iterating using pairs and assigning. + +___printValue (tab : ANY, name : string) + +recursively prints out all object values - if duplicates found, reference printed + +___merge (t : table, ... : tables) + +Shallow-merges a sequence of tables onto table t by iterating over each using +pairs and assigning. + +#### Internal Utilities - Not to Use + decodeCall + doOptionMerge + +### Attribution +parsing test suite from JSON_checker project of http://www.json.org/ +No listed license for these files in their package. diff -Nru lua-json-1.3.3/ReleaseNotes.txt lua-json-1.3.4/ReleaseNotes.txt --- lua-json-1.3.3/ReleaseNotes.txt 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/ReleaseNotes.txt 2017-02-01 04:44:11.000000000 +0000 @@ -1,31 +1,103 @@ -luajson v1.3.3 Release Notes +luajson v1.3.4 Release Notes ============================ User Visible Changes -------------------- + +Maintenance for older versions (ex: 1.0.x, 1.1.x, 1.2.x) will be on-demand. No +longer will changes be introduced there and trickled down. + The main changes for this release are: - * Allow objects with metatables to declare themselves as an array by - setting __is_luajson_array as true in the metatable. - * Pass all unit tests in Lua 5.2 (lunit tests had an issue) + * Lua 5.3 and LuaJIT 2.1-beta support added. + * LPEG 1.0.1 support verified. + * Documentation enhancements: + * README converted to MarkDown. + * Address utility method documentation to address exposed + public-use methods. + * Address utility method documentation to call out unsupported + internal methods. + * Address GitHub issue #38: + * A new allowEmptyElement option is available that will make + array and map building more forgiving for missing entries. Plans for next release ---------------------- -As declared in v1.3.2, a future release will have a stronger focus on decoder -performance. It may mean a reduction in flexibility by removing options and -breaking compatibility... so this would likely be either v1.4 or v2.0 +At this point there are no particular strong plans for next release. + +Enhancing error output and performance are goals, but not terribly high on my +priority list. -Updates since 1.3.2 +Updates since 1.3.3 =================== -Thomas Harning Jr (16): - all: - adds module metadata as suggested by fperrad +Thomas Harning Jr (65): base: - fixes link for luarocks download - updates rock creation tool to include tag version - encoder: - if __is_luajson_array is set on a metatable, consider the value as an array + drops obsolute SCM rockspecs + updates lunit tests to pass through interpreter + adds travis-ci build file + fixes travis + travis fixes - drop unsupported Lua5.2 lpeg versions and add missing make build + fixes regression test lua path + travis fixes - drop unsupported Lua5.2 lpeg versions and add missing make build + applies required branch list to travis + rewrite language as python for broader support of the .travis.yml + updates Travis-CI build structure to use sample + lua is always symlinked as the correct version + expands to newer versions of Lua/luajit + switch to lunitx due to expanded Lua 5.2, Lua 5.3 support + build: + reverses build order to assign greater importance to newer items + updates to LPEG 0.12.2 due to Lua5.3 compat patch + adds LPeg 1.0.0 and trims a build from 0.12.2 tree + ci: + updates travis.yml to allow feature branches + update used version of LuaRocks + replaces LPEG 1.0.0 testing with 1.0.1 testing + codecov: + apply report generation automatically + compat: + fixes unpack calls to lookup table.unpack before the 5.2-deprecated/removed unpack + decode+docs+tests: + adds support for (array/object/calls).allowEmptyElement to address GH #38 + decode.calls+tests: + handle trailingCommas in own setting vs borrowing 'array' configuration + decode.strings+tests: + fixes additionalEscapes to override builtin escapes and side-step escapeCheck needing to be altered + decoder: + drops unused 'expected' utility method + docs: + updates README to indicate updated testing results and drops mention of travis-ci pieces due to removal + cleans up reference for non-present functionality GH #37 and adds details for json.util + updates README to reflect new test LPEG platform and Lua 5.3.4 release + encode: + simplify encoder map building to current use case to enhance coverage + license: + updates copyright year + luacov: + update path to point to right location + not using luacov-coveralls + test: + update tests to not rely removed math.pow + update utf-8 handler to be more strict about integer division tests: - fixes lunit test to work with Lua 5.2 environment management + updates to Lua 5.2/5.3 requirements + updates more strongly to Lua 5.2/5.3 requirements by dropping _M usage + adds positive test case with nothrow to enhance test coverage + adds multiple registered calls and nested calls to enhance test coverage + enhances coverage for number parsing options + enhances coverage for strings.additionalEscapes decoding option + enhances coverage for NaN handling + enhances coverage for undefined and unregistered method encoding + travis: + synchronizes with moteus/lua-travis-example to fix LuaJIT builds + use hererocks for local install management + adds in coveralls coverage reporting + run coveralls in verbose mode + try global coveralls support + manually do codecov generation after transforming to relative paths + attempt downgrading luacov to 0.9.1 to fix line stats +Ewan Breakey (1): + -ungrouped- + Update README to use MarkDown diff -Nru lua-json-1.3.3/rockspecs/luajson-1.3.4-1.rockspec lua-json-1.3.4/rockspecs/luajson-1.3.4-1.rockspec --- lua-json-1.3.3/rockspecs/luajson-1.3.4-1.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/rockspecs/luajson-1.3.4-1.rockspec 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,44 @@ +package = "luajson" +version = "1.3.4-1" +source = { + url = "git://github.com/harningt/luajson.git", + tag = "1.3.4" +} +description = { + summary = "customizable JSON decoder/encoder", + detailed = [[ + LuaJSON is a customizable JSON decoder/encoder using + LPEG for parsing. + ]], + homepage = "http://github.com/harningt/luajson", + maintainer = "Thomas Harning ", + license = "MIT/X11" +} +dependencies = { + "lua >= 5.1", + "lpeg >= 0.8.1" +} +build = { + type = "module", + modules = { + ["json"] = "lua/json.lua", + ["json.decode"] = "lua/json/decode.lua", + ["json.decode.composite"] = "lua/json/decode/composite.lua", + ["json.decode.number"] = "lua/json/decode/number.lua", + ["json.decode.others"] = "lua/json/decode/others.lua", + ["json.decode.state"] = "lua/json/decode/state.lua", + ["json.decode.strings"] = "lua/json/decode/strings.lua", + ["json.decode.util"] = "lua/json/decode/util.lua", + ["json.encode"] = "lua/json/encode.lua", + ["json.encode.array"] = "lua/json/encode/array.lua", + ["json.encode.calls"] = "lua/json/encode/calls.lua", + ["json.encode.number"] = "lua/json/encode/number.lua", + ["json.encode.object"] = "lua/json/encode/object.lua", + ["json.encode.others"] = "lua/json/encode/others.lua", + ["json.encode.output"] = "lua/json/encode/output.lua", + ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", + ["json.encode.strings"] = "lua/json/encode/strings.lua", + ["json.util"] = "lua/json/util.lua" + } +} + diff -Nru lua-json-1.3.3/rockspecs/luajson-scm-1.rockspec lua-json-1.3.4/rockspecs/luajson-scm-1.rockspec --- lua-json-1.3.3/rockspecs/luajson-scm-1.rockspec 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/rockspecs/luajson-scm-1.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -package = "luajson" -version = "scm-1" -source = { - url = "git://repo.or.cz/luajson.git" -} -description = { - summary = "customizable JSON decoder/encoder", - detailed = [[ - LuaJSON is a customizable JSON decoder/encoder using - LPEG for parsing. - ]], - homepage = "http://gitrepo.or.cz/w/luajson.git", - maintainer = "Thomas Harning ", - license = "MIT/X11" -} -dependencies = { - "lua >= 5.1", - "lunit >= 0.4", - "lpeg >= 0.8.1" -} -build = { - type = "module", - modules = { - json = "src/json.lua", - ["json.util"] = "src/json/util.lua", - ["json.encode"] = "src/json/encode.lua", - ["json.decode"] = "src/json/decode.lua", - ["json.decode.array"] = "src/json/decode/array.lua", - ["json.decode.number"] = "src/json/decode/number.lua", - ["json.decode.object"] = "src/json/decode/object.lua", - ["json.decode.string"] = "src/json/decode/strings.lua", - ["json.decode.util"] = "src/json/decode/util.lua" - } -} diff -Nru lua-json-1.3.3/rockspecs/luajson-scm-2.rockspec lua-json-1.3.4/rockspecs/luajson-scm-2.rockspec --- lua-json-1.3.3/rockspecs/luajson-scm-2.rockspec 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/rockspecs/luajson-scm-2.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -package = "luajson" -version = "scm-1" -source = { - url = "git://github.com/harningt/luajson.git" -} -description = { - summary = "customizable JSON decoder/encoder", - detailed = [[ - LuaJSON is a customizable JSON decoder/encoder using - LPEG for parsing. - ]], - homepage = "http://github.com/harningt/luajson", - maintainer = "Thomas Harning ", - license = "MIT/X11" -} -dependencies = { - "lua >= 5.1", - "lunit >= 0.4", - "lpeg >= 0.8.1" -} -build = { - type = "module", - modules = { - json = "src/json.lua", - ["json.util"] = "src/json/util.lua", - ["json.decode"] = "src/json/decode.lua", - ["json.decode.array"] = "src/json/decode/array.lua", - ["json.decode.calls"] = "src/json/decode/calls.lua", - ["json.decode.number"] = "src/json/decode/number.lua", - ["json.decode.object"] = "src/json/decode/object.lua", - ["json.decode.others"] = "src/json/decode/others.lua", - ["json.decode.strings"] = "src/json/decode/strings.lua", - ["json.decode.util"] = "src/json/decode/util.lua", - ["json.encode"] = "src/json/encode.lua", - ["json.encode.array"] = "src/json/encode/array.lua", - ["json.encode.calls"] = "src/json/encode/calls.lua", - ["json.encode.number"] = "src/json/encode/number.lua", - ["json.encode.object"] = "src/json/encode/object.lua", - ["json.encode.others"] = "src/json/encode/others.lua", - ["json.encode.strings"] = "src/json/encode/strings.lua" - } -} diff -Nru lua-json-1.3.3/rockspecs/luajson-scm-3.rockspec lua-json-1.3.4/rockspecs/luajson-scm-3.rockspec --- lua-json-1.3.3/rockspecs/luajson-scm-3.rockspec 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/rockspecs/luajson-scm-3.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -package = "luajson" -version = "scm-3" -source = { - url = "git://github.com/harningt/luajson.git" -} -description = { - summary = "customizable JSON decoder/encoder", - detailed = [[ - LuaJSON is a customizable JSON decoder/encoder using - LPEG for parsing. - ]], - homepage = "http://github.com/harningt/luajson", - maintainer = "Thomas Harning ", - license = "MIT/X11" -} -dependencies = { - "lua >= 5.1", - "lunit >= 0.4", - "lpeg >= 0.8.1" -} -build = { - type = "module", - modules = { - ["json.decode.array"] = "lua/json/decode/array.lua", - ["json.decode.calls"] = "lua/json/decode/calls.lua", - ["json.decode.number"] = "lua/json/decode/number.lua", - ["json.decode.object"] = "lua/json/decode/object.lua", - ["json.decode.others"] = "lua/json/decode/others.lua", - ["json.decode.strings"] = "lua/json/decode/strings.lua", - ["json.decode.util"] = "lua/json/decode/util.lua", - ["json.decode"] = "lua/json/decode.lua", - ["json.encode.array"] = "lua/json/encode/array.lua", - ["json.encode.calls"] = "lua/json/encode/calls.lua", - ["json.encode.number"] = "lua/json/encode/number.lua", - ["json.encode.object"] = "lua/json/encode/object.lua", - ["json.encode.others"] = "lua/json/encode/others.lua", - ["json.encode.output"] = "lua/json/encode/output.lua", - ["json.encode.output_utility"] = "lua/json/encode/output_utility.lua", - ["json.encode.strings"] = "lua/json/encode/strings.lua", - ["json.encode"] = "lua/json/encode.lua", - ["json.util"] = "lua/json/util.lua", - ["json"] = "lua/json.lua" - } -} - diff -Nru lua-json-1.3.3/tests/.luacov lua-json-1.3.4/tests/.luacov --- lua-json-1.3.3/tests/.luacov 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/tests/.luacov 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,38 @@ +--- Global configuration file. Copy, customize and store in your +-- project folder as '.luacov' for project specific configuration +-- @class module +-- @name luacov.defaults +return { + + -- default filename to load for config options if not provided + -- only has effect in 'luacov.defaults.lua' + configfile = ".luacov", + + -- filename to store stats collected + statsfile = "luacov.stats.out", + + -- filename to store report + reportfile = "luacov.report.json", + + -- Run reporter on completion? (won't work for ticks) + runreport = false, + + -- Delete stats file after reporting? + deletestats = false, + + -- Patterns for files to include when reporting + -- all will be included if nothing is listed + -- (exclude overrules include, do not include + -- the .lua extension) + include = { + "/json$", + "/json/.+$", + }, + + -- Patterns for files to exclude when reporting + -- all will be included if nothing is listed + -- (exclude overrules include, do not include + -- the .lua extension) + exclude = { + }, +} diff -Nru lua-json-1.3.3/tests/lunit-calls.lua lua-json-1.3.4/tests/lunit-calls.lua --- lua-json-1.3.3/tests/lunit-calls.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-calls.lua 2017-02-01 04:44:11.000000000 +0000 @@ -8,7 +8,11 @@ -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) -module("lunit-calls", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-calls", 'seeall') +else + module("lunit-calls", lunit.testcase, package.seeall) +end function setup() -- Ensure that the decoder is reset @@ -102,11 +106,48 @@ function test_permitted() local strict = { calls = { - defs = { call = true } + defs = { call = true, other = true } } } local decoder = json.decode.getDecoder(strict) assert(decoder("call(1)").name == 'call') + assert(decoder("other(1)").name == 'other') +end + +function test_permitted_trailing() + local strict = { + calls = { + defs = { call = true, other = true } + } + } + local decoder = json.decode.getDecoder(strict) + assert(decoder("call(1,)").name == 'call') + assert(decoder("other(1,)").name == 'other') +end +function test_permitted_no_trailing() + local strict = { + calls = { + defs = { call = true, other = true }, + trailingComma = false + } + } + local decoder = json.decode.getDecoder(strict) + assert_error(function() + decoder("call(1,)") + end) + assert_error(function() + decoder("other(1,)") + end) +end +function test_permitted_nested() + local strict = { + calls = { + defs = { call = true, other = true } + } + } + local decoder = json.decode.getDecoder(strict) + assert(decoder("call(call(1))").name == 'call') + assert(decoder("other(call(1))").name == 'other') end function test_not_defined_fail() diff -Nru lua-json-1.3.3/tests/lunit-depth.lua lua-json-1.3.4/tests/lunit-depth.lua --- lua-json-1.3.3/tests/lunit-depth.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-depth.lua 2017-02-01 04:44:11.000000000 +0000 @@ -1,7 +1,11 @@ local lunit = require("lunit") local json = require("json") -module("lunit-depth", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-depth", 'seeall') +else + module("lunit-depth", lunit.testcase, package.seeall) +end local SAFE_DEPTH = 23 local SAFE_CALL_DEPTH = 31 diff -Nru lua-json-1.3.3/tests/lunit-empties-decode.lua lua-json-1.3.4/tests/lunit-empties-decode.lua --- lua-json-1.3.3/tests/lunit-empties-decode.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-empties-decode.lua 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,273 @@ +local json = require("json") +local lunit = require("lunit") + +-- Test module for handling the decoding with 'empties' allowed +if not module then + _ENV = lunit.module("lunit-empties-decode", 'seeall') +else + module("lunit-empties-decode", lunit.testcase, package.seeall) +end + +local options = { + array = { + allowEmptyElement = true + }, + calls = { + allowEmptyElement = true, + allowUndefined = true + }, + object = { + allowEmptyElement = true, + } +} +local options_notrailing = { + array = { + allowEmptyElement = true, + trailingComma = false + }, + calls = { + allowEmptyElement = true, + allowUndefined = true, + trailingComma = false + }, + object = { + allowEmptyElement = true, + trailingComma = false + } +} +local options_simple_null = { + array = { + allowEmptyElement = true + }, + calls = { + allowEmptyElement = true, + allowUndefined = true + }, + object = { + allowEmptyElement = true, + }, + others = { + null = false, + undefined = false + } +} + +function test_decode_array_with_only_null() + local result = assert(json.decode('[null]', options_simple_null)) + assert_nil(result[1]) + assert_equal(1, result.n) + local result = assert(json.decode('[null]', options)) + assert_equal(json.util.null, result[1]) + assert_equal(1, #result) +end + +function test_decode_array_with_empties() + local result = assert(json.decode('[,]', options_simple_null)) + assert_nil(result[1]) + assert_equal(1, result.n) + local result = assert(json.decode('[,]', options)) + assert_equal(json.util.undefined, result[1]) + assert_equal(1, #result) + + local result = assert(json.decode('[,]', options_notrailing)) + assert_equal(json.util.undefined, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(2, #result) +end + +function test_decode_array_with_null() + local result = assert(json.decode('[1, null, 3]', options_simple_null)) + assert_equal(1, result[1]) + assert_nil(result[2]) + assert_equal(3, result[3]) + assert_equal(3, result.n) + local result = assert(json.decode('[1, null, 3]', options)) + assert_equal(1, result[1]) + assert_equal(json.util.null, result[2]) + assert_equal(3, result[3]) +end +function test_decode_array_with_empty() + local result = assert(json.decode('[1,, 3]', options_simple_null)) + assert_equal(1, result[1]) + assert_nil(result[2]) + assert_equal(3, result[3]) + assert_equal(3, result.n) + local result = assert(json.decode('[1,, 3]', options)) + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(3, result[3]) +end + +function test_decode_small_array_with_trailing_null() + local result = assert(json.decode('[1, null]', options_simple_null)) + assert_equal(1, result[1]) + assert_nil(result[2]) + assert_equal(2, result.n) + local result = assert(json.decode('[1, ]', options_simple_null)) + assert_equal(1, result[1]) + assert_equal(1, #result) + local result = assert(json.decode('[1, ]', options)) + assert_equal(1, result[1]) + assert_equal(1, #result) + local result = assert(json.decode('[1, ]', options_notrailing)) + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(2, #result) +end + +function test_decode_array_with_trailing_null() + local result = assert(json.decode('[1, null, 3, null]', options_simple_null)) + assert_equal(1, result[1]) + assert_nil(result[2]) + assert_equal(3, result[3]) + assert_nil(result[4]) + assert_equal(4, result.n) + local result = assert(json.decode('[1, null, 3, null]', options)) + assert_equal(1, result[1]) + assert_equal(json.util.null, result[2]) + assert_equal(3, result[3]) + assert_equal(json.util.null, result[4]) + assert_equal(4, #result) + local result = assert(json.decode('[1, , 3, ]', options)) + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(3, result[3]) + assert_equal(3, #result) + local result = assert(json.decode('[1, , 3, ]', options_notrailing)) + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(3, result[3]) + assert_equal(json.util.undefined, result[4]) + assert_equal(4, #result) +end + +function test_decode_object_with_null() + local result = assert(json.decode('{x: null}', options_simple_null)) + assert_nil(result.x) + assert_nil(next(result)) + + local result = assert(json.decode('{x: null}', options)) + assert_equal(json.util.null, result.x) + + local result = assert(json.decode('{x: }', options_simple_null)) + assert_nil(result.x) + assert_nil(next(result)) + + local result = assert(json.decode('{x: }', options)) + assert_equal(json.util.undefined, result.x) + + -- Handle the trailing comma case + local result = assert(json.decode('{x: ,}', options_simple_null)) + assert_nil(result.x) + assert_nil(next(result)) + + local result = assert(json.decode('{x: ,}', options)) + assert_equal(json.util.undefined, result.x) + + -- NOTE: Trailing comma must be allowed explicitly in this case + assert_error(function() + json.decode('{x: ,}', options_notrailing) + end) + + -- Standard setup doesn't allow empties + assert_error(function() + json.decode('{x: }') + end) +end +function test_decode_bigger_object_with_null() + local result = assert(json.decode('{y: 1, x: null}', options_simple_null)) + assert_equal(1, result.y) + assert_nil(result.x) + + local result = assert(json.decode('{y: 1, x: null}', options)) + assert_equal(1, result.y) + assert_equal(json.util.null, result.x) + + local result = assert(json.decode('{y: 1, x: }', options_simple_null)) + assert_equal(1, result.y) + assert_nil(result.x) + local result = assert(json.decode('{x: , y: 1}', options_simple_null)) + assert_equal(1, result.y) + assert_nil(result.x) + + local result = assert(json.decode('{y: 1, x: }', options)) + assert_equal(1, result.y) + assert_equal(json.util.undefined, result.x) + + local result = assert(json.decode('{x: , y: 1}', options)) + assert_equal(1, result.y) + assert_equal(json.util.undefined, result.x) + + -- Handle the trailing comma case + local result = assert(json.decode('{y: 1, x: , }', options_simple_null)) + assert_equal(1, result.y) + assert_nil(result.x) + local result = assert(json.decode('{x: , y: 1, }', options_simple_null)) + assert_equal(1, result.y) + assert_nil(result.x) + + local result = assert(json.decode('{y: 1, x: ,}', options)) + assert_equal(1, result.y) + assert_equal(json.util.undefined, result.x) + + local result = assert(json.decode('{x: , y: 1, }', options)) + assert_equal(1, result.y) + assert_equal(json.util.undefined, result.x) + + -- NOTE: Trailing comma must be allowed explicitly in this case as there is no such thing as an "empty" key:value pair + assert_error(function() + json.decode('{y: 1, x: ,}', options_notrailing) + end) + assert_error(function() + json.decode('{x: , y: 1, }', options_notrailing) + end) +end + +function test_decode_call_with_empties() + local result = assert(json.decode('call(,)', options_simple_null)) + result = result.parameters + assert_nil(result[1]) + assert_equal(1, result.n) + local result = assert(json.decode('call(,)', options)) + result = result.parameters + assert_equal(json.util.undefined, result[1]) + assert_equal(1, #result) + + local result = assert(json.decode('call(,)', options_notrailing)) + result = result.parameters + assert_equal(json.util.undefined, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(2, #result) +end + + + +function test_call_with_empties_and_trailing() + local result = assert(json.decode('call(1, null, 3, null)', options_simple_null)) + result = result.parameters + assert_equal(1, result[1]) + assert_nil(result[2]) + assert_equal(3, result[3]) + assert_nil(result[4]) + assert_equal(4, result.n) + local result = assert(json.decode('call(1, null, 3, null)', options)) + result = result.parameters + assert_equal(1, result[1]) + assert_equal(json.util.null, result[2]) + assert_equal(3, result[3]) + assert_equal(json.util.null, result[4]) + assert_equal(4, #result) + local result = assert(json.decode('call(1, , 3, )', options)) + result = result.parameters + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(3, result[3]) + assert_equal(3, #result) + local result = assert(json.decode('call(1, , 3, )', options_notrailing)) + result = result.parameters + assert_equal(1, result[1]) + assert_equal(json.util.undefined, result[2]) + assert_equal(3, result[3]) + assert_equal(json.util.undefined, result[4]) + assert_equal(4, #result) +end diff -Nru lua-json-1.3.3/tests/lunit-encoderfunc.lua lua-json-1.3.4/tests/lunit-encoderfunc.lua --- lua-json-1.3.3/tests/lunit-encoderfunc.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-encoderfunc.lua 2017-02-01 04:44:11.000000000 +0000 @@ -2,10 +2,15 @@ local lunit = require("lunit") local math = require("math") local testutil = require("testutil") +local unpack = require("table").unpack or unpack local setmetatable = setmetatable -module("lunit-encoderfunc", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-encoderfunc", 'seeall') +else + module("lunit-encoderfunc", lunit.testcase, package.seeall) +end local function build_call(name, parameters) return json.util.buildCall(name, unpack(parameters, parameters.n)) diff -Nru lua-json-1.3.3/tests/lunit-encoding.lua lua-json-1.3.4/tests/lunit-encoding.lua --- lua-json-1.3.3/tests/lunit-encoding.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-encoding.lua 2017-02-01 04:44:11.000000000 +0000 @@ -1,7 +1,11 @@ local json = require("json") local lunit = require("lunit") -module("lunit-encoding", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-encoding", 'seeall') +else + module("lunit-encoding", lunit.testcase, package.seeall) +end function test_cloned_array_sibling() local obj = {} @@ -75,3 +79,13 @@ assert_equal("[]", json.encode(setmetatable({}, {__is_luajson_array = true}))) assert_equal("[]", json.encode(json.util.InitArray({}))) end + +function test_undefined() + assert_equal("[undefined]", json.encode({ json.util.undefined })) +end + +function test_unknown() + assert_error("Expected attempting to encode an unregistered function to fail", function() + json.encode({ function() end }) + end) +end diff -Nru lua-json-1.3.3/tests/lunit-nothrow-decode.lua lua-json-1.3.4/tests/lunit-nothrow-decode.lua --- lua-json-1.3.3/tests/lunit-nothrow-decode.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-nothrow-decode.lua 2017-02-01 04:44:11.000000000 +0000 @@ -2,7 +2,11 @@ local lunit = require("lunit") -- Test module for handling the simple decoding that behaves more like expected -module("lunit-nothrow-decode", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-nothrow-decode", 'seeall') +else + module("lunit-nothrow-decode", lunit.testcase, package.seeall) +end function test_decode_nothrow_bad_data() assert_nil((json.decode('x', {nothrow = true}))) @@ -12,3 +16,11 @@ assert_nil((json.decode('["\\xzz"]', {nothrow = true}))) end +function test_decode_nothrow_ok_data() + assert_not_nil((json.decode('"x"', {nothrow = true}))) + assert_not_nil((json.decode('{x:"x"}', {nothrow = true}))) + assert_not_nil((json.decode('["x"]', {nothrow = true}))) + assert_not_nil((json.decode('[1.0]', {nothrow = true}))) + assert_not_nil((json.decode('["\\u00FF"]', {nothrow = true}))) +end + diff -Nru lua-json-1.3.3/tests/lunit-numbers.lua lua-json-1.3.4/tests/lunit-numbers.lua --- lua-json-1.3.3/tests/lunit-numbers.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-numbers.lua 2017-02-01 04:44:11.000000000 +0000 @@ -8,22 +8,35 @@ -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) -module("lunit-numbers", lunit.testcase, package.seeall) +local TEST_ENV +if not module then + _ENV = lunit.module("lunit-numbers", 'seeall') + TEST_ENV = _ENV +else + module("lunit-numbers", lunit.testcase, package.seeall) + TEST_ENV = _M +end function setup() -- Ensure that the decoder is reset _G["decode"] = json.decode.getDecoder(false) end -local function assert_near(expect, received) +local function is_near(expect, received) local pctDiff if expect == received then pctDiff = 0 else pctDiff = math.abs(1 - expect / received) end - local msg = ("expected '%s' but was '%s' .. '%s'%% apart"):format(expect, received, pctDiff * 100) - assert(pctDiff < 0.000001, msg) + if pctDiff < 0.000001 then + return true + else + return false, ("expected '%s' but was '%s' .. '%s'%% apart"):format(expect, received, pctDiff * 100) + end +end +local function assert_near(expect, received) + assert(is_near(expect, received)) end local function test_simple(num) assert_near(num, decode(tostring(num))) @@ -35,14 +48,24 @@ assert_near(num, decode(string.format('%e', num))) assert_near(num, decode(string.format('%E', num))) end +local function test_scientific_denied(num) + local decode = json.decode.getDecoder({ number = { exp = false } }) + assert_error_match("Exponent-denied error did not match", "Exponents.*denied", function() + decode(string.format('%e', num)) + end) + assert_error_match("Exponent-denied error did not match", "Exponents.*denied", function() + decode(string.format('%E', num)) + end) +end local numbers = { 0, 1, -1, math.pi, -math.pi } math.randomseed(0xDEADBEEF) +local pow = math.pow or load("return function(a, b) return a ^ b end")() -- Add sequence of numbers at low/high end of value-set for i = -300,300,60 do - numbers[#numbers + 1] = math.random() * math.pow(10, i) - numbers[#numbers + 1] = -math.random() * math.pow(10, i) + numbers[#numbers + 1] = math.random() * pow(10, i) + numbers[#numbers + 1] = -math.random() * pow(10, i) end local function get_number_tester(f) @@ -53,9 +76,35 @@ end end +local function test_fraction(num) + assert_near(num, decode(string.format("%f", num))) +end +local function test_fraction_denied(num) + local decode = json.decode.getDecoder({ number = { frac = false } }) + local formatted = string.format('%f', num) + assert_error_match("Fraction-denied error did not match for " .. formatted, "Fractions.*denied", function() + decode(formatted) + end) +end +local function get_number_fraction_tester(f) + return function () + for _, v in ipairs(numbers) do + -- Fractional portion must be present + local formatted = string.format("%f", v) + -- San check that the formatted value is near the desired value + if nil ~= formatted:find("%.") and is_near(v, tonumber(formatted)) then + f(v) + end + end + end +end + test_simple_numbers = get_number_tester(test_simple) test_simple_numbers_w_encode = get_number_tester(test_simple_w_encode) test_simple_numbers_scientific = get_number_tester(test_scientific) +test_simple_numbers_scientific_denied = get_number_tester(test_scientific_denied) +test_simple_numbers_fraction_only = get_number_fraction_tester(test_fraction) +test_simple_numbers_fraction_denied_only = get_number_fraction_tester(test_fraction_denied) function test_infinite_nostrict() assert_equal(math.huge, decode("Infinity")) @@ -69,6 +118,7 @@ assert_true(value ~= value) local value = decode("NaN") assert_true(value ~= value) + assert_equal("NaN", encode(decode("NaN"))) end function test_expression() @@ -139,13 +189,13 @@ return testutil.buildFailedPatchedDecoder(f, strictDecoder) end -- SETUP CHECKS FOR SEQUENCE OF DECODERS -for k, v in pairs(_M) do +for k, v in pairs(TEST_ENV) do if k:match("^test_") and not k:match("_gen$") and not k:match("_only$") then if k:match("_nostrict") then - _M[k .. "_strict_gen"] = buildFailedStrictDecoder(v) + TEST_ENV[k .. "_strict_gen"] = buildFailedStrictDecoder(v) else - _M[k .. "_strict_gen"] = buildStrictDecoder(v) + TEST_ENV[k .. "_strict_gen"] = buildStrictDecoder(v) end - _M[k .. "_hex_gen"] = testutil.buildPatchedDecoder(v, hexDecoder) + TEST_ENV[k .. "_hex_gen"] = testutil.buildPatchedDecoder(v, hexDecoder) end end diff -Nru lua-json-1.3.3/tests/lunit-simple-decode.lua lua-json-1.3.4/tests/lunit-simple-decode.lua --- lua-json-1.3.3/tests/lunit-simple-decode.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-simple-decode.lua 2017-02-01 04:44:11.000000000 +0000 @@ -2,7 +2,11 @@ local lunit = require("lunit") -- Test module for handling the simple decoding that behaves more like expected -module("lunit-simple-decode", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-simple-decode", 'seeall') +else + module("lunit-simple-decode", lunit.testcase, package.seeall) +end function test_decode_simple_undefined() assert_nil(json.decode('undefined', json.decode.simple)) diff -Nru lua-json-1.3.3/tests/lunit-strings.lua lua-json-1.3.4/tests/lunit-strings.lua --- lua-json-1.3.3/tests/lunit-strings.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-strings.lua 2017-02-01 04:44:11.000000000 +0000 @@ -9,7 +9,11 @@ local error = error -module("lunit-strings", lunit.testcase, package.seeall) +if not module then + _ENV = lunit.module("lunit-strings", 'seeall') +else + module("lunit-strings", lunit.testcase, package.seeall) +end local function assert_table_equal(expect, t) if type(expect) ~= 'table' then diff -Nru lua-json-1.3.3/tests/lunit-tests.lua lua-json-1.3.4/tests/lunit-tests.lua --- lua-json-1.3.3/tests/lunit-tests.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/lunit-tests.lua 2017-02-01 04:44:11.000000000 +0000 @@ -1,10 +1,18 @@ local json = require("json") local lunit = require("lunit") local testutil = require("testutil") +local lpeg = require("lpeg") -- DECODE NOT 'local' due to requirement for testutil to access it decode = json.decode.getDecoder(false) -module("lunit-tests", lunit.testcase, package.seeall) +local TEST_ENV +if not module then + _ENV = lunit.module("lunit-tests", 'seeall') + TEST_ENV = _ENV +else + module("lunit-tests", lunit.testcase, package.seeall) + TEST_ENV = _M +end function setup() _G["decode"] = json.decode.getDecoder(false) @@ -35,6 +43,13 @@ assert_equal('-Infinity', json.encode(1/0, {preProcess = function(x) return -x end})) end +function test_additionalEscapes_only() + -- Test that additionalEscapes is processed on its own - side-stepping normal processing + assert_equal("Hello\\?", json.decode([["\S"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("S")) / "Hello\\?" } })) + -- Test that additionalEscapes overrides any builtin handling + assert_equal("Hello\\?", json.decode([["\n"]], { strings = { additionalEscapes = lpeg.C(lpeg.P("n")) / "Hello\\?" } })) +end + local strictDecoder = json.decode.getDecoder(true) local function buildStrictDecoder(f) @@ -44,12 +59,12 @@ return testutil.buildFailedPatchedDecoder(f, strictDecoder) end -- SETUP CHECKS FOR SEQUENCE OF DECODERS -for k, v in pairs(_M) do - if k:match("^test_") and not k:match("_gen$") then +for k, v in pairs(TEST_ENV) do + if k:match("^test_") and not k:match("_gen$") and not k:match("_only$") then if k:match("_nostrict") then - _M[k .. "_strict_gen"] = buildFailedStrictDecoder(v) + TEST_ENV[k .. "_strict_gen"] = buildFailedStrictDecoder(v) else - _M[k .. "_strict_gen"] = buildStrictDecoder(v) + TEST_ENV[k .. "_strict_gen"] = buildStrictDecoder(v) end end end diff -Nru lua-json-1.3.3/tests/testutil.lua lua-json-1.3.4/tests/testutil.lua --- lua-json-1.3.3/tests/testutil.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/testutil.lua 2017-02-01 04:44:11.000000000 +0000 @@ -7,16 +7,21 @@ local function setDecoder(d) _G.decode = d end -module("testutil", package.seeall) -function buildPatchedDecoder(f, newDecoder) + +local function buildPatchedDecoder(f, newDecoder) return function() setDecoder(newDecoder) f() end end -function buildFailedPatchedDecoder(f, newDecoder) +local function buildFailedPatchedDecoder(f, newDecoder) return function() setDecoder(newDecoder) assert_error(f) end end + +return { + buildPatchedDecoder = buildPatchedDecoder, + buildFailedPatchedDecoder = buildFailedPatchedDecoder +} diff -Nru lua-json-1.3.3/tests/utf8_processor.lua lua-json-1.3.4/tests/utf8_processor.lua --- lua-json-1.3.3/tests/utf8_processor.lua 2015-08-16 21:09:35.000000000 +0000 +++ lua-json-1.3.4/tests/utf8_processor.lua 2017-02-01 04:44:11.000000000 +0000 @@ -2,7 +2,9 @@ local string = string -module("utf8_processor") +local floor = require("math").floor + +local _ENV = nil local function encode_utf(codepoint) if codepoint > 0x10FFFF then @@ -10,7 +12,7 @@ elseif codepoint > 0xFFFF then -- Surrogate pair needed codepoint = codepoint - 0x10000 - local first, second = codepoint / 0x0400 + 0xD800, codepoint % 0x0400 + 0xDC00 + local first, second = floor(codepoint / 0x0400) + 0xD800, codepoint % 0x0400 + 0xDC00 return ("\\u%.4X\\u%.4X"):format(first, second) else return ("\\u%.4X"):format(codepoint) @@ -45,6 +47,10 @@ local utf8_decode_pattern = lpeg.Cs(utf8^0) * -1 -function process(s) +local function process(s) return utf8_decode_pattern:match(s) end + +return { + process = process +} diff -Nru lua-json-1.3.3/.travis.yml lua-json-1.3.4/.travis.yml --- lua-json-1.3.3/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ lua-json-1.3.4/.travis.yml 2017-02-01 04:44:11.000000000 +0000 @@ -0,0 +1,64 @@ +# Pull in python for access to pip for hererocks +language: python + +sudo: false + +branches: + only: + - master + - next + - 1.2.x + - 1.1.x + - 1.0.x + +env: + global: + - LUAROCKS=2.4.2 + matrix: + - LPEG=1.0.1-1 LUA="luajit 2.1" + - LPEG=1.0.1-1 LUA="luajit 2.0" + - LPEG=1.0.1-1 LUA="lua 5.3" + - LPEG=1.0.1-1 LUA="lua 5.2" + - LPEG=1.0.1-1 LUA="lua 5.1" + - LPEG=0.12.2-1 LUA="luajit 2.1" + - LPEG=0.12.2-1 LUA="luajit 2.0" + - LPEG=0.12.2-1 LUA="lua 5.3" + - LPEG=0.12.2-1 LUA="lua 5.2" + - LPEG=0.12.2-1 LUA="lua 5.1" + - LPEG=0.10.2-1 LUA="luajit 2.0" + - LPEG=0.10.2-1 LUA="lua 5.2" + - LPEG=0.10.2-1 LUA="lua 5.1" + - LPEG=0.9-1 LUA="luajit 2.0" + - LPEG=0.9-1 LUA="lua 5.1" + - LPEG=0.8.1-1 LUA="luajit 2.0" + - LPEG=0.8.1-1 LUA="lua 5.1" + - LPEG=0.7-3 LUA="luajit 2.0" + - LPEG=0.7-3 LUA="lua 5.1" + +branches: + only: + - master + - /^feature[/]/ + +before_install: + - pip install hererocks + - hererocks here -r $LUAROCKS --$LUA + - export PATH=$(pwd)/here/bin:$PATH + - luarocks install luacov + - luarocks install lunitx + - luarocks install luafilesystem + - luarocks install lpeg $LPEG + +script: + - make LUA_BIN=lua LUNIT_BIN=lunit.sh LUA_INIT="require('luarocks.loader');require('luacov')" check + +after_success: + # Rework the stats file and generate + - sed -e "s|../lua/|lua/|" < tests/luacov.stats.out > luacov.stats.out + - luacov + - bash <(curl -s https://codecov.io/bash) + +notifications: + email: + on_success: change + on_failure: always