summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/util.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-04-18 10:46:04 +0200
committerJo-Philipp Wich <jo@mein.io>2018-04-18 16:21:27 +0200
commitf52c8d0b7f0eeec4259992182103d859f454639b (patch)
treecdea06cb8b6af4b3b07e9f042639a302763b1b49 /modules/luci-base/luasrc/util.lua
parent3f0abd936df2803f85d93c303ed9d589ff5b0b16 (diff)
luci-base: switch to lucihttp.urldecode() and lucihttp.urlencode()
Drop the Lua implementation in luci.http.protocol and use the optimized C variants of liblucihttp instead. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/util.lua')
-rw-r--r--modules/luci-base/luasrc/util.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua
index 06a889cfc..36bbaaf47 100644
--- a/modules/luci-base/luasrc/util.lua
+++ b/modules/luci-base/luasrc/util.lua
@@ -10,6 +10,7 @@ local string = require "string"
local coroutine = require "coroutine"
local tparser = require "luci.template.parser"
local json = require "luci.jsonc"
+local lhttp = require "lucihttp"
local _ubus = require "ubus"
local _ubus_connection = nil
@@ -160,6 +161,25 @@ function pcdata(value)
return value and tparser.pcdata(tostring(value))
end
+function urlencode(value)
+ if value ~= nil then
+ local str = tostring(value)
+ return lhttp.urlencode(str, lhttp.ENCODE_IF_NEEDED + lhttp.ENCODE_FULL)
+ or str
+ end
+ return nil
+end
+
+function urldecode(value, decode_plus)
+ if value ~= nil then
+ local flag = decode_plus and lhttp.DECODE_PLUS or 0
+ local str = tostring(value)
+ return lhttp.urldecode(str, lhttp.DECODE_IF_NEEDED + flag)
+ or str
+ end
+ return nil
+end
+
function striptags(value)
return value and tparser.striptags(tostring(value))
end