From 821e6aa045ecbb22dbc96d2dafe5f7ae1c839762 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 12 Jul 2014 15:09:39 +0200 Subject: =?UTF-8?q?[conf]=20validate=20config=20variable=20=E2=80=9Cformat?= =?UTF-8?q?s=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a validation function that checks whether the value is indeed a list of comma-separated identifiers. Also, duplicate and invalid entries are dropped from the result. --- src/luaotfload-configuration.lua | 46 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/luaotfload-configuration.lua') diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index ff90f68..937b050 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -31,6 +31,8 @@ local stringexplode = string.explode local table = table local tableappend = table.append local tablecopy = table.copy +local tableconcat = table.concat +local tabletohash = table.tohash local math = math local mathfloor = math.floor @@ -44,6 +46,7 @@ local osgetenv = os.getenv local lpeg = require "lpeg" local lpegmatch = lpeg.match +local lpegsplitter = lpeg.splitat "," local kpse = kpse local kpseexpand_path = kpse.expand_path @@ -91,6 +94,11 @@ local config_paths = { { kpse_t, "luaotfload.conf" }, } +local valid_formats = tabletohash { + "otf", "ttc", "ttf", "dfont", "afm", "pfb", "pfa", +} + + ------------------------------------------------------------------------------- --- DEFAULTS ------------------------------------------------------------------------------- @@ -253,7 +261,43 @@ end local option_spec = { db = { - formats = { in_t = string_t, }, + formats = { + in_t = string_t, + out_t = string_t, + transform = function (f) + local fields = { lpegmatch (lpegsplitter, f) } + + --- check validity + if not fields then + logreport ("both", 0, "conf", + "Expected list of identifiers, got %q.", f) + return nil + end + + --- strip dupes + local known = { } + local result = { } + for i = 1, #fields do + local field = fields[i] + if known[field] ~= true then + --- yet unknown, tag as seen + known[field] = true + --- include in output if valid + if valid_formats[field] == true then + result[#result + 1] = field + else + logreport ("both", 4, "conf", + "Invalid font format identifier %q, ignoring.", field) + end + end + end + if #result == 0 then + --- force defaults + return nil + end + return tableconcat (result, ",") + end + }, reload = { in_t = boolean_t, }, scan_local = { in_t = boolean_t, }, skip_read = { in_t = boolean_t, }, -- cgit v1.2.3