mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-05 18:44:03 +08:00
✨ Sync 2026-09-11 23:47:18
This commit is contained in:
1 parent
be72c4a194
commit
8141aa4b54
89 files changed
+3680
-3045
No files matched your search
@@ -0,0 +1,33 @@
|
||||
local M = {}
|
||||
|
||||
function M.normalize_https_url(value)
|
||||
local url = tostring(value or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
||||
if url == "" or url:match("[%z\1-\32\127'\"\\<>]") then return nil end
|
||||
if not url:match("^https://[a-zA-Z0-9%-%._~:/?#%[%]@!$&()*+,;=]+$") then return nil end
|
||||
local authority = url:match("^https://([^/%?#]+)")
|
||||
if not authority or authority:find("@", 1, true) then return nil end
|
||||
|
||||
local host, port
|
||||
if authority:sub(1, 1) == "[" then
|
||||
host, port = authority:match("^(%[[0-9a-fA-F:%.]+%]):?(%d*)$")
|
||||
else
|
||||
host, port = authority:match("^([a-zA-Z0-9][a-zA-Z0-9%.%-]*):?(%d*)$")
|
||||
end
|
||||
if not host or host == "" then return nil end
|
||||
if port and port ~= "" then
|
||||
local number = tonumber(port)
|
||||
if not number or number < 1 or number > 65535 then return nil end
|
||||
end
|
||||
return url:gsub("/+$", "")
|
||||
end
|
||||
|
||||
function M.html_attr(value)
|
||||
return tostring(value or "")
|
||||
:gsub("&", "&")
|
||||
:gsub("<", "<")
|
||||
:gsub(">", ">")
|
||||
:gsub('"', """)
|
||||
:gsub("'", "'")
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user