/usr/share/lua/5.1/pl/url.lua is in lua-penlight 1.3.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | --- Python-style URL quoting library.
--
-- @module pl.url
local M = {}
--- Quote the url.
-- @string s the string
-- @bool quote_plus Use quote_plus rules
function M.quote(s, quote_plus)
function url_quote_char(c)
return string.format("%%%02X", string.byte(c))
end
if not s or not type(s) == "string" then
return s
end
s = s:gsub("\n", "\r\n")
s = s:gsub("([^A-Za-z0-9 %-_%./])", url_quote_char)
if quote_plus then
s = s:gsub(" ", "+")
s = s:gsub("/", url_quote_char)
else
s = s:gsub(" ", "%%20")
end
return s
end
--- Unquote the url.
-- @string s the string
function M.unquote(s)
if not s or not type(s) == "string" then
return s
end
s = s:gsub("+", " ")
s = s:gsub("%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
s = s:gsub("\r\n", "\n")
return s
end
return M
|