From 68521fca04e9b2ae801cc2daa4f920a2c43bc03f Mon Sep 17 00:00:00 2001 From: Sven Roederer Date: Sat, 6 Jul 2019 14:18:15 +0200 Subject: [PATCH] luci-base(-libs): move pcdata() and striptags() from util- to xml-class To complete the previous commit these functions are defined in the resulting luci-base package but are also used in the new luci-base-libs package. So move them into the new xml-module of the new package. Signed-off-by: Sven Roederer --- docs/api/index.html | 9 + docs/api/modules/luci.dispatcher.html | 4 + docs/api/modules/luci.http.conditionals.html | 4 + docs/api/modules/luci.http.date.html | 4 + docs/api/modules/luci.http.html | 4 + docs/api/modules/luci.http.mime.html | 4 + docs/api/modules/luci.i18n.html | 4 + docs/api/modules/luci.ip.cidr.html | 4 + docs/api/modules/luci.ip.html | 4 + docs/api/modules/luci.json.html | 4 + docs/api/modules/luci.jsonc.html | 4 + docs/api/modules/luci.jsonc.parser.html | 4 + docs/api/modules/luci.model.ipkg.html | 4 + docs/api/modules/luci.model.uci.html | 4 + docs/api/modules/luci.rpcc.html | 4 + docs/api/modules/luci.rpcc.ruci.html | 4 + docs/api/modules/luci.sys.html | 4 + docs/api/modules/luci.sys.init.html | 4 + docs/api/modules/luci.sys.iptparser.html | 4 + docs/api/modules/luci.sys.net.html | 4 + docs/api/modules/luci.sys.process.html | 4 + docs/api/modules/luci.sys.user.html | 4 + docs/api/modules/luci.sys.wifi.html | 4 + docs/api/modules/luci.util.html | 78 +---- docs/api/modules/luci.xml.html | 321 +++++++++++++++++++ docs/api/modules/nixio.CHANGELOG.html | 4 + docs/api/modules/nixio.CryptoHash.html | 4 + docs/api/modules/nixio.File.html | 4 + docs/api/modules/nixio.README.html | 4 + docs/api/modules/nixio.Socket.html | 4 + docs/api/modules/nixio.TLSContext.html | 4 + docs/api/modules/nixio.TLSSocket.html | 4 + docs/api/modules/nixio.UnifiedIO.html | 4 + docs/api/modules/nixio.bin.html | 4 + docs/api/modules/nixio.bit.html | 4 + docs/api/modules/nixio.crypto.html | 4 + docs/api/modules/nixio.fs.html | 4 + docs/api/modules/nixio.html | 4 + libs/luci-lib-base/luasrc/util.lua | 14 +- libs/luci-lib-base/luasrc/util.luadoc | 6 + modules/luci-base/luasrc/xml.lua | 26 ++ modules/luci-base/luasrc/xml.luadoc | 23 ++ 42 files changed, 545 insertions(+), 72 deletions(-) create mode 100644 docs/api/modules/luci.xml.html create mode 100644 modules/luci-base/luasrc/xml.lua create mode 100644 modules/luci-base/luasrc/xml.luadoc diff --git a/docs/api/index.html b/docs/api/index.html index 5e3f3c211a..66a27a33bc 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • @@ -328,6 +332,11 @@ LuCI system utilities / wifi related functions. + + luci.xml + + + nixio diff --git a/docs/api/modules/luci.dispatcher.html b/docs/api/modules/luci.dispatcher.html index ea33a5c706..32cb49573b 100644 --- a/docs/api/modules/luci.dispatcher.html +++ b/docs/api/modules/luci.dispatcher.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.http.conditionals.html b/docs/api/modules/luci.http.conditionals.html index 8c940bd3f6..14ee627f68 100644 --- a/docs/api/modules/luci.http.conditionals.html +++ b/docs/api/modules/luci.http.conditionals.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.http.date.html b/docs/api/modules/luci.http.date.html index 1ec5beb8b7..680dd43137 100644 --- a/docs/api/modules/luci.http.date.html +++ b/docs/api/modules/luci.http.date.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.http.html b/docs/api/modules/luci.http.html index 4731727849..3e8799e744 100644 --- a/docs/api/modules/luci.http.html +++ b/docs/api/modules/luci.http.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.http.mime.html b/docs/api/modules/luci.http.mime.html index 85eaf53ab0..756b0727ae 100644 --- a/docs/api/modules/luci.http.mime.html +++ b/docs/api/modules/luci.http.mime.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.i18n.html b/docs/api/modules/luci.i18n.html index 0f315bebd5..5ba44b4c01 100644 --- a/docs/api/modules/luci.i18n.html +++ b/docs/api/modules/luci.i18n.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.ip.cidr.html b/docs/api/modules/luci.ip.cidr.html index ae6c61dc5d..cfe1909352 100644 --- a/docs/api/modules/luci.ip.cidr.html +++ b/docs/api/modules/luci.ip.cidr.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.ip.html b/docs/api/modules/luci.ip.html index 0599396b6f..8d503bd655 100644 --- a/docs/api/modules/luci.ip.html +++ b/docs/api/modules/luci.ip.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.json.html b/docs/api/modules/luci.json.html index db2d1da3f4..5885556d50 100644 --- a/docs/api/modules/luci.json.html +++ b/docs/api/modules/luci.json.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.jsonc.html b/docs/api/modules/luci.jsonc.html index 79deb933d7..f6ab990faa 100644 --- a/docs/api/modules/luci.jsonc.html +++ b/docs/api/modules/luci.jsonc.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.jsonc.parser.html b/docs/api/modules/luci.jsonc.parser.html index 709cb9afc5..54e1e487d5 100644 --- a/docs/api/modules/luci.jsonc.parser.html +++ b/docs/api/modules/luci.jsonc.parser.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.model.ipkg.html b/docs/api/modules/luci.model.ipkg.html index a0af3187b7..e97097db51 100644 --- a/docs/api/modules/luci.model.ipkg.html +++ b/docs/api/modules/luci.model.ipkg.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.model.uci.html b/docs/api/modules/luci.model.uci.html index c1eaf5f813..84b6ecc1b8 100644 --- a/docs/api/modules/luci.model.uci.html +++ b/docs/api/modules/luci.model.uci.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.rpcc.html b/docs/api/modules/luci.rpcc.html index 18065788bd..10d628ff43 100644 --- a/docs/api/modules/luci.rpcc.html +++ b/docs/api/modules/luci.rpcc.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.rpcc.ruci.html b/docs/api/modules/luci.rpcc.ruci.html index 7348f1932b..598020df7e 100644 --- a/docs/api/modules/luci.rpcc.ruci.html +++ b/docs/api/modules/luci.rpcc.ruci.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.html b/docs/api/modules/luci.sys.html index b86d280fba..f601e17dd3 100644 --- a/docs/api/modules/luci.sys.html +++ b/docs/api/modules/luci.sys.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.init.html b/docs/api/modules/luci.sys.init.html index e2c51f9531..b178cafca3 100644 --- a/docs/api/modules/luci.sys.init.html +++ b/docs/api/modules/luci.sys.init.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.iptparser.html b/docs/api/modules/luci.sys.iptparser.html index 5928281cf4..aa9f7ce1c5 100644 --- a/docs/api/modules/luci.sys.iptparser.html +++ b/docs/api/modules/luci.sys.iptparser.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.net.html b/docs/api/modules/luci.sys.net.html index e7802bb244..bf1bb54aa6 100644 --- a/docs/api/modules/luci.sys.net.html +++ b/docs/api/modules/luci.sys.net.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.process.html b/docs/api/modules/luci.sys.process.html index d3664817cc..ec42ecadd9 100644 --- a/docs/api/modules/luci.sys.process.html +++ b/docs/api/modules/luci.sys.process.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.user.html b/docs/api/modules/luci.sys.user.html index b2307ad385..27b13ccbbf 100644 --- a/docs/api/modules/luci.sys.user.html +++ b/docs/api/modules/luci.sys.user.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.sys.wifi.html b/docs/api/modules/luci.sys.wifi.html index 6c893244c1..37e7053fd7 100644 --- a/docs/api/modules/luci.sys.wifi.html +++ b/docs/api/modules/luci.sys.wifi.html @@ -124,6 +124,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/luci.util.html b/docs/api/modules/luci.util.html index f8baddf410..1fc2539928 100644 --- a/docs/api/modules/luci.util.html +++ b/docs/api/modules/luci.util.html @@ -124,6 +124,10 @@
  • luci.util
  • +
  • + luci.xml +
  • +
  • nixio
  • @@ -342,10 +346,11 @@ value or 0 if the unit is unknown. - pcdata (value) + pcdata (value) -Create valid XML PCDATA from given string. +Create valid XML PCDATA from given string. +This is a wrapper for luci.xml.pcdata(). @@ -409,10 +414,11 @@ Strips unnecessary lua bytecode from given string. - striptags (value) + striptags (value) -Strip HTML tags from given string. +Strip HTML tags from given string. +This is a wrapper for luci.xml.striptags(). @@ -1178,38 +1184,6 @@ Number containing the canonical value -
    pcdata (value)
    -
    - - -Create valid XML PCDATA from given string. - - - -

    Parameters

    -
      - -
    • - value: String value containing the data to escape -
    • - -
    - - - - - - -

    Return value:

    -String value containing the escaped data - - - -
    - - - -
    perror (obj)
    @@ -1524,38 +1498,6 @@ String value containing the stripped lua byte code -
    striptags (value)
    -
    - - -Strip HTML tags from given string. - - - -

    Parameters

    -
      - -
    • - value: String containing the HTML text -
    • - -
    - - - - - - -

    Return value:

    -String with HTML tags stripped of - - - -
    - - - -
    threadlocal ()
    diff --git a/docs/api/modules/luci.xml.html b/docs/api/modules/luci.xml.html new file mode 100644 index 0000000000..63a91e4eb6 --- /dev/null +++ b/docs/api/modules/luci.xml.html @@ -0,0 +1,321 @@ + + + + Reference + + + + + +
    + +
    + +
    +
    +
    + +
    + + + +
    + +

    Class luci.xml

    + +

    + + + + + + + +

    Functions

    + + + + + + + + + + + + +
    pcdata (value) + +Create valid XML PCDATA from given string.
    striptags (value) + +Strip HTML tags from given string.
    + + + + + + +
    +
    + + +

    Functions

    +
    + + + +
    pcdata (value)
    +
    + + +Create valid XML PCDATA from given string. + + + +

    Parameters

    +
      + +
    • + value: String value containing the data to escape +
    • + +
    + + + + + + +

    Return value:

    +String value containing the escaped data + + + +
    + + + + +
    striptags (value)
    +
    + + +Strip HTML tags from given string. + + + +

    Parameters

    +
      + +
    • + value: String containing the HTML text +
    • + +
    + + + + + + +

    Return value:

    +String with HTML tags stripped of + + + +
    + + + +
    + + + + + +
    + +
    + +
    +

    Valid XHTML 1.0!

    +
    + +
    + + diff --git a/docs/api/modules/nixio.CHANGELOG.html b/docs/api/modules/nixio.CHANGELOG.html index 94b44a5ca6..0def9a4512 100644 --- a/docs/api/modules/nixio.CHANGELOG.html +++ b/docs/api/modules/nixio.CHANGELOG.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.CryptoHash.html b/docs/api/modules/nixio.CryptoHash.html index 7d2f48b1e5..a333c407d5 100644 --- a/docs/api/modules/nixio.CryptoHash.html +++ b/docs/api/modules/nixio.CryptoHash.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.File.html b/docs/api/modules/nixio.File.html index 7a7500a773..b46a317bc1 100644 --- a/docs/api/modules/nixio.File.html +++ b/docs/api/modules/nixio.File.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.README.html b/docs/api/modules/nixio.README.html index e140659cc7..b8481ef55a 100644 --- a/docs/api/modules/nixio.README.html +++ b/docs/api/modules/nixio.README.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.Socket.html b/docs/api/modules/nixio.Socket.html index 185099125d..f1d48ef2b6 100644 --- a/docs/api/modules/nixio.Socket.html +++ b/docs/api/modules/nixio.Socket.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.TLSContext.html b/docs/api/modules/nixio.TLSContext.html index c84d318955..247670c561 100644 --- a/docs/api/modules/nixio.TLSContext.html +++ b/docs/api/modules/nixio.TLSContext.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.TLSSocket.html b/docs/api/modules/nixio.TLSSocket.html index 5d6098a9f5..20cdaa55a1 100644 --- a/docs/api/modules/nixio.TLSSocket.html +++ b/docs/api/modules/nixio.TLSSocket.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.UnifiedIO.html b/docs/api/modules/nixio.UnifiedIO.html index 6410ffb42e..8521e3e2af 100644 --- a/docs/api/modules/nixio.UnifiedIO.html +++ b/docs/api/modules/nixio.UnifiedIO.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.bin.html b/docs/api/modules/nixio.bin.html index c8ef018317..aeb14eb53e 100644 --- a/docs/api/modules/nixio.bin.html +++ b/docs/api/modules/nixio.bin.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.bit.html b/docs/api/modules/nixio.bit.html index 419736363c..d0ce111db2 100644 --- a/docs/api/modules/nixio.bit.html +++ b/docs/api/modules/nixio.bit.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.crypto.html b/docs/api/modules/nixio.crypto.html index b91fe28c1d..498620bcdf 100644 --- a/docs/api/modules/nixio.crypto.html +++ b/docs/api/modules/nixio.crypto.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.fs.html b/docs/api/modules/nixio.fs.html index c9d34591c2..956c0e93a8 100644 --- a/docs/api/modules/nixio.fs.html +++ b/docs/api/modules/nixio.fs.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/docs/api/modules/nixio.html b/docs/api/modules/nixio.html index bf93619c91..36895486c7 100644 --- a/docs/api/modules/nixio.html +++ b/docs/api/modules/nixio.html @@ -126,6 +126,10 @@ luci.util +
  • + luci.xml +
  • +
  • nixio
  • diff --git a/libs/luci-lib-base/luasrc/util.lua b/libs/luci-lib-base/luasrc/util.lua index a30e8b72f3..38e00ad83b 100644 --- a/libs/luci-lib-base/luasrc/util.lua +++ b/libs/luci-lib-base/luasrc/util.lua @@ -159,8 +159,12 @@ end -- String and data manipulation routines -- +-- compatibility wrapper for xml.pcdata function pcdata(value) - return value and tparser.pcdata(tostring(value)) + local xml = require "luci.xml" + + perror("luci.util.pcdata() has been replaced by luci.xml.pcdata() - Please update your code.") + return xml.pcdata(value) end function urlencode(value) @@ -182,8 +186,12 @@ function urldecode(value, decode_plus) return nil end +-- compatibility wrapper for xml.striptags function striptags(value) - return value and tparser.striptags(tostring(value)) + local xml = require "luci.xml" + + perror("luci.util.striptags() has been replaced by luci.xml.striptags() - Please update your code.") + return xml.striptags(value) end function shellquote(value) @@ -343,8 +351,6 @@ function parse_units(ustr) end -- also register functions above in the central string class for convenience -string.pcdata = pcdata -string.striptags = striptags string.split = split string.trim = trim string.cmatch = cmatch diff --git a/libs/luci-lib-base/luasrc/util.luadoc b/libs/luci-lib-base/luasrc/util.luadoc index 4ec68dd1ef..3168d9c220 100644 --- a/libs/luci-lib-base/luasrc/util.luadoc +++ b/libs/luci-lib-base/luasrc/util.luadoc @@ -70,10 +70,13 @@ Recursively dumps a table to stdout, useful for testing and debugging. ---[[ Create valid XML PCDATA from given string. +This is just a compatibility wrapper for luci.xml.padata() + @class function @name pcdata @param value String value containing the data to escape @return String value containing the escaped data +@see luci.xml.pcdata ]] ---[[ @@ -100,10 +103,13 @@ URL-encode given string. ---[[ Strip HTML tags from given string. +This is just a compatibility wrapper for luci.xml.striptags() + @class function @name striptags @param value String containing the HTML text @return String with HTML tags stripped of +@see luci.xml.striptags ]] ---[[ diff --git a/modules/luci-base/luasrc/xml.lua b/modules/luci-base/luasrc/xml.lua new file mode 100644 index 0000000000..30b37210bd --- /dev/null +++ b/modules/luci-base/luasrc/xml.lua @@ -0,0 +1,26 @@ +-- Copyright 2008 Steven Barth +-- Licensed to the public under the Apache License 2.0. + +local tparser = require "luci.template.parser" +local string = require "string" + +local tostring = tostring + +module "luci.xml" + +-- +-- String and data manipulation routines +-- + +function pcdata(value) + return value and tparser.pcdata(tostring(value)) +end + +function striptags(value) + return value and tparser.striptags(tostring(value)) +end + + +-- also register functions above in the central string class for convenience +string.pcdata = pcdata +string.striptags = striptags diff --git a/modules/luci-base/luasrc/xml.luadoc b/modules/luci-base/luasrc/xml.luadoc new file mode 100644 index 0000000000..58de533966 --- /dev/null +++ b/modules/luci-base/luasrc/xml.luadoc @@ -0,0 +1,23 @@ +---[[ +LuCI utility functions. +]] +module "luci.xml" + +---[[ +Create valid XML PCDATA from given string. + +@class function +@name pcdata +@param value String value containing the data to escape +@return String value containing the escaped data +]] + +---[[ +Strip HTML tags from given string. + +@class function +@name striptags +@param value String containing the HTML text +@return String with HTML tags stripped of +]] + -- 2.30.2