Comparison

tools/generate_format_spec.lua @ 12039:e0a8c5b1ab4f

util.format: Ensure metatable __tostring results are also sanitized
author Kim Alvefur <zash@zash.se>
date Mon, 13 Dec 2021 16:34:55 +0100
parent 12037:82f6a0b0a425
comparison
equal deleted inserted replaced
12038:4e54334febc1 12039:e0a8c5b1ab4f
16 ["number"] = { 97; -12345; 1.5; 73786976294838206464; math.huge; 2147483647 }; 16 ["number"] = { 97; -12345; 1.5; 73786976294838206464; math.huge; 2147483647 };
17 ["string"] = { "hello"; "foo \1\2\3 bar"; "nödåtgärd"; string.sub("nödåtgärd", 1, -4) }; 17 ["string"] = { "hello"; "foo \1\2\3 bar"; "nödåtgärd"; string.sub("nödåtgärd", 1, -4) };
18 ["function"] = { function() end }; 18 ["function"] = { function() end };
19 -- ["userdata"] = {}; 19 -- ["userdata"] = {};
20 ["thread"] = { coroutine.create(function() end) }; 20 ["thread"] = { coroutine.create(function() end) };
21 ["table"] = { {} }; 21 ["table"] = { {}, setmetatable({},{__tostring=function ()return "foo \1\2\3 bar"end}) };
22 }; 22 };
23 local example_strings = setmetatable({ 23 local example_strings = setmetatable({
24 ["nil"] = { "nil" }; 24 ["nil"] = { "nil" };
25 ["function"] = { "function() end" }; 25 ["function"] = { "function() end" };
26 ["number"] = { "97"; "-12345"; "1.5"; "73786976294838206464"; "math.huge"; "2147483647" }; 26 ["number"] = { "97"; "-12345"; "1.5"; "73786976294838206464"; "math.huge"; "2147483647" };
27 ["thread"] = { "coroutine.create(function() end)" }; 27 ["thread"] = { "coroutine.create(function() end)" };
28 ["table"] = { "{ }", "setmetatable({},{__tostring=function ()return \"foo \\1\\2\\3 bar\"end})" }
28 }, { __index = function() return {} end }); 29 }, { __index = function() return {} end });
29 for _, lua_type in ipairs(types) do 30 for _, lua_type in ipairs(types) do
30 print(string.format("\t\tdescribe(\"%s\", function ()", lua_type)); 31 print(string.format("\t\tdescribe(\"%s\", function ()", lua_type));
31 local examples = example_values[lua_type]; 32 local examples = example_values[lua_type];
32 for fmt in ("cdiouxXaAeEfgGqs"):gmatch(".") do 33 for fmt in ("cdiouxXaAeEfgGqs"):gmatch(".") do