diff options
author | Thibault Charbonnier <thibaultcha@me.com> | 2016-12-16 18:27:49 -0800 |
---|---|---|
committer | Yichun Zhang (agentzh) <agentzh@gmail.com> | 2016-12-17 20:14:47 -0800 |
commit | a61d7840ba2d79df8cb73d8c864a99d0eb06d580 (patch) | |
tree | d410e0db9567b283e801ef4cb0e1b15517601da1 /tests | |
parent | a18d6999d82ba34493892a609c00937b81c84355 (diff) | |
download | lua-cjson-a61d7840ba2d79df8cb73d8c864a99d0eb06d580.tar.gz lua-cjson-a61d7840ba2d79df8cb73d8c864a99d0eb06d580.tar.bz2 lua-cjson-a61d7840ba2d79df8cb73d8c864a99d0eb06d580.zip |
bugfix: preserve 'empty_array_mt' behavior upon multiple loadings of the module.
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/agentzh.t | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/tests/agentzh.t b/tests/agentzh.t index e76f910..3b0ecf1 100644 --- a/tests/agentzh.t +++ b/tests/agentzh.t | |||
@@ -113,7 +113,31 @@ print(cjson.encode(data)) | |||
113 | 113 | ||
114 | 114 | ||
115 | 115 | ||
116 | === TEST 9: & in JSON | 116 | === TEST 9: multiple calls to lua_cjson_new (1/2) |
117 | --- lua | ||
118 | local cjson = require "cjson" | ||
119 | package.loaded["cjson"] = nil | ||
120 | require "cjson" | ||
121 | local arr = setmetatable({}, cjson.empty_array_mt) | ||
122 | print(cjson.encode(arr)) | ||
123 | --- out | ||
124 | [] | ||
125 | |||
126 | |||
127 | |||
128 | === TEST 10: multiple calls to lua_cjson_new (2/2) | ||
129 | --- lua | ||
130 | local cjson = require "cjson.safe" | ||
131 | -- load another cjson instance (not in package.loaded) | ||
132 | require "cjson" | ||
133 | local arr = setmetatable({}, cjson.empty_array_mt) | ||
134 | print(cjson.encode(arr)) | ||
135 | --- out | ||
136 | [] | ||
137 | |||
138 | |||
139 | |||
140 | === TEST 11: & in JSON | ||
117 | --- lua | 141 | --- lua |
118 | local cjson = require "cjson" | 142 | local cjson = require "cjson" |
119 | local a="[\"a=1&b=2\"]" | 143 | local a="[\"a=1&b=2\"]" |
@@ -124,7 +148,7 @@ print(cjson.encode(b)) | |||
124 | 148 | ||
125 | 149 | ||
126 | 150 | ||
127 | === TEST 10: default and max precision | 151 | === TEST 12: default and max precision |
128 | --- lua | 152 | --- lua |
129 | local math = require "math" | 153 | local math = require "math" |
130 | local cjson = require "cjson" | 154 | local cjson = require "cjson" |