35 lines
792 B
Lua
35 lines
792 B
Lua
local SocketUrl = require"socket.url"
|
|
|
|
local function urlescape(str)
|
|
return SocketUrl.escape(str)
|
|
end
|
|
|
|
local function urlunescape(str)
|
|
return SocketUrl.unescape(str)
|
|
end
|
|
|
|
local function urlspunescape(str)
|
|
return urlunescape(str:gsub("%+", "%%20"))
|
|
end
|
|
|
|
local function htmlescape(str)
|
|
return (str:gsub("%&", "&"):gsub("%<", "<"):gsub("%>", ">"):gsub("%\"", """):gsub("%'", "'"))
|
|
end
|
|
|
|
local function shellescape(str)
|
|
return "'" .. str:gsub("'", "'\"'\"'") .. "'"
|
|
end
|
|
|
|
local function cssescape(str)
|
|
return '"' .. str:gsub('"', '\\"'):gsub('\\', '\\\\') .. '"'
|
|
end
|
|
|
|
return {
|
|
urlescape = urlescape,
|
|
urlunescape = urlunescape,
|
|
urlspunescape = urlspunescape,
|
|
htmlescape = htmlescape,
|
|
shellescape = shellescape,
|
|
patternescape = patternescape,
|
|
cssescape = cssescape,
|
|
} |