From 0e63b6f673544a52078da0981a245d6a03ab9dbd Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Mon, 13 Sep 2010 05:19:36 +0300 Subject: Sanitize color before attempting to use it Right now it just checks the number if fields, may be we should check if it is a valid hex color value as well. --- otfl-font-clr.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'otfl-font-clr.lua') diff --git a/otfl-font-clr.lua b/otfl-font-clr.lua index a6cf63f..dc14b2c 100644 --- a/otfl-font-clr.lua +++ b/otfl-font-clr.lua @@ -15,8 +15,22 @@ local initializers, format = fonts.initializers, string.format table.insert(fonts.triggers,"color") function initializers.common.color(tfmdata,value) + local sanitized + if value then - tfmdata.color = tostring(value) + if #value == 6 or #value == 8 then + sanitized = value + elseif #value == 7 then + _, _, sanitized = value:find("(......)") + elseif #value > 8 then + _, _, sanitized = value:find("(........)") + else + -- broken color code ignored, issue a warning? + end + end + + if sanitized then + tfmdata.color = sanitized add_color_callback() end end -- cgit v1.2.3