diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-12 15:09:39 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-12 15:15:47 +0200 |
commit | 821e6aa045ecbb22dbc96d2dafe5f7ae1c839762 (patch) | |
tree | fa00b04ae17613ed15b30aeb019c3e644842d4bc /src | |
parent | 992a8e8b1967486291cc1f480fd3ff83d904576c (diff) | |
download | luaotfload-821e6aa045ecbb22dbc96d2dafe5f7ae1c839762.tar.gz |
[conf] validate config variable “formats”
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/luaotfload-configuration.lua | 46 |
1 files changed, 45 insertions, 1 deletions
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, }, |