summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/util.lua
diff options
context:
space:
mode:
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