diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-02-12 08:28:21 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-02-12 08:31:08 +0100 |
commit | 4141243762aafb7960d67f871c97907307005f87 (patch) | |
tree | ccf4ae22fec68cc96324a45ab445936c573217b9 /modules | |
parent | 83df3eb6c7678a5988bc8c9942e9892a24ab6967 (diff) |
luci-base: dispatcher: support raw values in attr() and ifattr()
Extend the attr() and ifattr() template functions to take an optional
further parameter indicating that the passed value should not be escaped.
This is needed for cases where the input already is escaped through
other means, e.g. when the value was previously filtered through the
striptags() template helper.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/luasrc/dispatcher.lua | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/modules/luci-base/luasrc/dispatcher.lua b/modules/luci-base/luasrc/dispatcher.lua index d85cb5824..626a46dfd 100644 --- a/modules/luci-base/luasrc/dispatcher.lua +++ b/modules/luci-base/luasrc/dispatcher.lua @@ -328,7 +328,7 @@ function dispatch(request) assert(media, "No valid theme found") end - local function _ifattr(cond, key, val) + local function _ifattr(cond, key, val, noescape) if cond then local env = getfenv(3) local scope = (type(env.self) == "table") and env.self @@ -339,13 +339,16 @@ function dispatch(request) val = util.serialize_json(val) end end - return string.format( - ' %s="%s"', tostring(key), - util.pcdata(tostring( val - or (type(env[key]) ~= "function" and env[key]) - or (scope and type(scope[key]) ~= "function" and scope[key]) - or "" )) - ) + + val = tostring(val or + (type(env[key]) ~= "function" and env[key]) or + (scope and type(scope[key]) ~= "function" and scope[key]) or "") + + if noescape ~= true then + val = util.pcdata(val) + end + + return string.format(' %s="%s"', tostring(key), val) else return '' end |