From aaaf475528ee1c1f12a2dd6d73aa95ecfc2adacc Mon Sep 17 00:00:00 2001 From: actions Date: Sat, 20 Jul 2024 05:00:06 +0800 Subject: [PATCH] luci-app-passwall: sync upstream last commit: https://github.com/xiaorouji/openwrt-passwall/commit/0eb890e9e6d3f660cfbe2925927927d8cf7a741c --- .../model/cbi/passwall/client/rule_list.lua | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua index 92a9178d1..906c4ca8c 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua @@ -38,9 +38,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local hosts= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end) for index, host in ipairs(hosts) do - if host:find("#") and host:find("#") == 1 then + if host:sub(1, 1) == "#" then return value end if not datatypes.hostname(host) then @@ -66,9 +67,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local ipmasks= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end) for index, ipmask in ipairs(ipmasks) do - if ipmask:find("#") and ipmask:find("#") == 1 then + if ipmask:sub(1, 1) == "#" then return value end if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then @@ -96,9 +98,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local hosts= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end) for index, host in ipairs(hosts) do - if host:find("#") and host:find("#") == 1 then + if host:sub(1, 1) == "#" then return value end if not datatypes.hostname(host) then @@ -124,9 +127,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local ipmasks= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end) for index, ipmask in ipairs(ipmasks) do - if ipmask:find("#") and ipmask:find("#") == 1 then + if ipmask:sub(1, 1) == "#" then return value end if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then @@ -152,9 +156,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local hosts= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end) for index, host in ipairs(hosts) do - if host:find("#") and host:find("#") == 1 then + if host:sub(1, 1) == "#" then return value end if not datatypes.hostname(host) then @@ -180,9 +185,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local ipmasks= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end) for index, ipmask in ipairs(ipmasks) do - if ipmask:find("#") and ipmask:find("#") == 1 then + if ipmask:sub(1, 1) == "#" then return value end if not ( datatypes.ipmask4(ipmask) or datatypes.ipmask6(ipmask) ) then @@ -208,9 +214,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local ipmasks= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end) for index, ipmask in ipairs(ipmasks) do - if ipmask:find("#") and ipmask:find("#") == 1 then + if ipmask:sub(1, 1) == "#" then return value end if not datatypes.ipmask4(ipmask) then @@ -236,9 +243,10 @@ o.remove = function(self, section, value) end o.validate = function(self, value) local ipmasks= {} + value = value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n") string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(ipmasks, w) end) for index, ipmask in ipairs(ipmasks) do - if ipmask:find("#") and ipmask:find("#") == 1 then + if ipmask:sub(1, 1) == "#" then return value end if not datatypes.ipmask6(ipmask) then @@ -257,7 +265,7 @@ o.cfgvalue = function(self, section) return fs.readfile(hosts) or "" end o.write = function(self, section, value) - fs.writefile(hosts, value:gsub("\r\n", "\n")) + fs.writefile(hosts, value:gsub("^%s+", ""):gsub("%s+$","\n"):gsub("\r\n","\n"):gsub("[ \t]*\n[ \t]*", "\n")) end o.remove = function(self, section, value) fs.writefile(hosts, "")