aboutsummaryrefslogtreecommitdiffstats
path: root/util/termcolours.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-28 15:03:01 +0100
committerKim Alvefur <zash@zash.se>2016-02-28 15:03:01 +0100
commit341876f588178a69fe62a92858b946f35c4308e0 (patch)
tree7f731acf4dd34c150127c33d0ca2d422f4a90eef /util/termcolours.lua
parent71d4a7236175764bb262f6cce728b32c4f59ad8a (diff)
downloadprosody-341876f588178a69fe62a92858b946f35c4308e0.tar.gz
prosody-341876f588178a69fe62a92858b946f35c4308e0.zip
util.termcolours: Validate color codes, fixes traceback
Diffstat (limited to 'util/termcolours.lua')
-rw-r--r--util/termcolours.lua9
1 files changed, 7 insertions, 2 deletions
diff --git a/util/termcolours.lua b/util/termcolours.lua
index a0fee7ce..dcdc994d 100644
--- a/util/termcolours.lua
+++ b/util/termcolours.lua
@@ -15,6 +15,9 @@ local tonumber = tonumber;
local ipairs = ipairs;
local io_write = io.write;
local m_floor = math.floor;
+local type = type;
+local setmetatable = setmetatable;
+local pairs = pairs;
local windows;
if os.getenv("WINDIR") then
@@ -76,8 +79,10 @@ local function hex2rgb(hex)
end
setmetatable(stylemap, { __index = function(_, style)
- local g = style:sub(7) == " background" and "48;5;" or "38;5;";
- return g .. color(hex2rgb(style));
+ if type(style) == "string" and style:find("%x%x%x%x%x%x") == 1 then
+ local g = style:sub(7) == " background" and "48;5;" or "38;5;";
+ return g .. color(hex2rgb(style));
+ end
end } );
local csscolors = {