diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-12-02 10:44:10 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-12-02 10:44:10 +0100 |
commit | ea9f25b63ee0d9a380cf74c65061c3977cad3b2f (patch) | |
tree | f152a2622de5e21372aaa813e0d2e13ecaeda033 /modules/luci-base/luasrc | |
parent | 9c9118566cb885a9a4298717a5a24eb92bfc8310 (diff) | |
parent | 829467b62748e8c4fb587636801fa03165f72e8a (diff) |
Merge pull request #561 from cshore/pull-request-fstab-improvements
Pull request fstab improvements
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r-- | modules/luci-base/luasrc/util.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua index 787bc66f90..5bf0beb6c2 100644 --- a/modules/luci-base/luasrc/util.lua +++ b/modules/luci-base/luasrc/util.lua @@ -151,6 +151,28 @@ function striptags(value) return value and tparser.striptags(tostring(value)) end +-- for bash, ash and similar shells single-quoted strings are taken +-- literally except for single quotes (which terminate the string) +-- (and the exception noted below for dash (-) at the start of a +-- command line parameter). +function shellsqescape(value) + local res + res, _ = string.gsub(res, "'", "'\\''") + return res +end + +-- bash, ash and other similar shells interpret a dash (-) at the start +-- of a command-line parameters as an option indicator regardless of +-- whether it is inside a single-quoted string. It must be backlash +-- escaped to resolve this. This requires in some funky special-case +-- handling. It may actually be a property of the getopt function +-- rather than the shell proper. +function shellstartsqescape(value) + res, _ = string.gsub(value, "^\-", "\\-") + res, _ = string.gsub(res, "^-", "\-") + return shellsqescape(value) +end + -- containing the resulting substrings. The optional max parameter specifies -- the number of bytes to process, regardless of the actual length of the given -- string. The optional last parameter, regex, specifies whether the separator |