aboutsummaryrefslogtreecommitdiffstats
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
commitdb5175995b4661a14255f3275f7ee3d4efbf6ce0 (patch)
tree7f731acf4dd34c150127c33d0ca2d422f4a90eef
parent6ebfda549383872b983982f2ab472053195e27c5 (diff)
downloadprosody-db5175995b4661a14255f3275f7ee3d4efbf6ce0.tar.gz
prosody-db5175995b4661a14255f3275f7ee3d4efbf6ce0.zip
util.termcolours: Validate color codes, fixes traceback
-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 = {