ikibooru/html.lua
2024-06-01 17:40:11 +03:00

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("%&", "&amp;"):gsub("%<", "&lt;"):gsub("%>", "&gt;"):gsub("%\"", "&quot;"):gsub("%'", "&#x27;"))
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,
}