Software /
code /
prosody
Changeset
7205:a6c4530c1bc0
util.termcolours: Validate color codes, fixes traceback
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Feb 2016 15:03:01 +0100 |
parents | 7204:ab2b7496a617 |
children | 7206:1c005878db55 |
files | util/termcolours.lua |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/util/termcolours.lua Sat Feb 27 16:56:34 2016 +0100 +++ b/util/termcolours.lua Sun Feb 28 15:03:01 2016 +0100 @@ -15,6 +15,9 @@ 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 @@ 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 = {