From fe0d762f11c8c3aa01f457f8a54684f7d4c9c3cb Mon Sep 17 00:00:00 2001 From: mutlusun Date: Sat, 21 Jan 2017 18:14:17 +0100 Subject: [PATCH] review changes #1 (argument escaping and removing goto) --- helpers.lua | 2 +- widgets/bat_freebsd.lua | 3 ++- widgets/net_freebsd.lua | 20 ++++++++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/helpers.lua b/helpers.lua index 33aa3d3..6c475e6 100644 --- a/helpers.lua +++ b/helpers.lua @@ -216,7 +216,7 @@ end function helpers.sysctl_table(syspath) return setmetatable({ _path = syspath }, { __index = function(table, index) - local path = "sysctl -n " .. table._path .. "." .. index + local path = "sysctl -n " .. helpers.shellquote(table._path .. "." .. index) local f = io.popen(path) if f then local s = f:read("*all") diff --git a/widgets/bat_freebsd.lua b/widgets/bat_freebsd.lua index 079997c..682bd4b 100644 --- a/widgets/bat_freebsd.lua +++ b/widgets/bat_freebsd.lua @@ -3,6 +3,7 @@ local setmetatable = setmetatable local tonumber = tonumber local io = { popen = io.popen } local math = { floor = math.floor } +local helpers = require("vicious.helpers") local string = { gmatch = string.gmatch, gsub = string.gsub, @@ -15,7 +16,7 @@ local bat_freebsd = {} local function worker(format, warg) local battery = warg or "batt" local bat_info = {} - local f = io.popen("acpiconf -i " .. battery) + local f = io.popen("acpiconf -i " .. helpers.shellquote(battery)) for line in f:lines("*line") do for key,value in string.gmatch(line, "(.+):%s+(.+)") do bat_info[key] = value diff --git a/widgets/net_freebsd.lua b/widgets/net_freebsd.lua index f1c3331..155a1b0 100644 --- a/widgets/net_freebsd.lua +++ b/widgets/net_freebsd.lua @@ -28,19 +28,15 @@ local function worker(format, warg) local now = os.time() for line in f:lines() do - if line:find("