1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 06:33:23 +00:00

Forbid mutating empty_json_array

It's definitely still possible (rawset), but should prevent people
accidentally trying to modify it when they shouldn't.
This commit is contained in:
SquidDev 2019-05-30 20:01:09 +01:00
parent 0cb659d78c
commit e839ef54af
2 changed files with 12 additions and 1 deletions

View File

@ -240,7 +240,11 @@ local function serializeImpl( t, tTracking, sIndent )
end
end
empty_json_array = {}
empty_json_array = setmetatable({}, {
__newindex = function()
error("attempt to mutate textutils.empty_json_array", 2)
end
})
local function serializeJSONImpl( t, tTracking, bNBTStyle )
local sType = type(t)

View File

@ -20,6 +20,13 @@ describe("The textutils library", function()
end)
end)
describe("textutils.empty_json_array", function()
it("is immutable", function()
expect.error(function() textutils.empty_json_array[1] = true end)
:eq("textutils_spec.lua:25: attempt to mutate textutils.empty_json_array")
end)
end)
describe("textutils.unserialise", function()
it("validates arguments", function()
textutils.unserialise("")