Comparison

util/openssl.lua @ 7021:f436446661ca

util.openssl: Move quoting and tostring call into escape function
author Kim Alvefur <zash@zash.se>
date Wed, 23 Dec 2015 08:42:02 +0100
parent 6902:d2d7ad2563f9
child 7022:3252c107c91a
comparison
equal deleted inserted replaced
7020:6ab9c691c4c6 7021:f436446661ca
142 end 142 end
143 end 143 end
144 144
145 do -- Lua to shell calls. 145 do -- Lua to shell calls.
146 local function shell_escape(s) 146 local function shell_escape(s)
147 return s:gsub("'",[['\'']]); 147 return "'" .. tostring(s):gsub("'",[['\'']]) .. "'";
148 end 148 end
149 149
150 local function serialize(f,o) 150 local function serialize(f,o)
151 local r = {"openssl", f}; 151 local r = {"openssl", f};
152 for k,v in pairs(o) do 152 for k,v in pairs(o) do
153 if type(k) == "string" then 153 if type(k) == "string" then
154 t_insert(r, ("-%s"):format(k)); 154 t_insert(r, ("-%s"):format(k));
155 if v ~= true then 155 if v ~= true then
156 t_insert(r, ("'%s'"):format(shell_escape(tostring(v)))); 156 t_insert(r, shell_escape(v));
157 end 157 end
158 end 158 end
159 end 159 end
160 for _,v in ipairs(o) do 160 for _,v in ipairs(o) do
161 t_insert(r, ("'%s'"):format(shell_escape(tostring(v)))); 161 t_insert(r, shell_escape(v));
162 end 162 end
163 return t_concat(r, " "); 163 return t_concat(r, " ");
164 end 164 end
165 165
166 local os_execute = os.execute; 166 local os_execute = os.execute;