mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
Merge pull request #238 from hleuwer/master
Fix URL parsing of userinfo containing # character.
This commit is contained in:
commit
88b13a825b
10
src/url.lua
10
src/url.lua
@ -131,11 +131,6 @@ function _M.parse(url, default)
|
||||
if not url or url == "" then return nil, "invalid url" end
|
||||
-- remove whitespace
|
||||
-- url = string.gsub(url, "%s", "")
|
||||
-- get fragment
|
||||
url = string.gsub(url, "#(.*)$", function(f)
|
||||
parsed.fragment = f
|
||||
return ""
|
||||
end)
|
||||
-- get scheme
|
||||
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
||||
function(s) parsed.scheme = s; return "" end)
|
||||
@ -144,6 +139,11 @@ function _M.parse(url, default)
|
||||
parsed.authority = n
|
||||
return ""
|
||||
end)
|
||||
-- get fragment
|
||||
url = string.gsub(url, "#(.*)$", function(f)
|
||||
parsed.fragment = f
|
||||
return ""
|
||||
end)
|
||||
-- get query string
|
||||
url = string.gsub(url, "%?(.*)", function(q)
|
||||
parsed.query = q
|
||||
|
@ -90,6 +90,75 @@ local check_parse_url = function(gaba)
|
||||
end
|
||||
|
||||
print("testing URL parsing")
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass$%?#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass$%?#wd",
|
||||
password = "pass$%?#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass?#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass?#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass?#wd",
|
||||
password = "pass?#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass-wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass-wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass-wd",
|
||||
password = "pass-wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass#wd",
|
||||
password = "pass#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass#wd@host:port/path;params?query",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass#wd",
|
||||
password = "pass#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
}
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
@ -608,9 +677,9 @@ check_parse_path("eu/tu", { "eu", "tu" })
|
||||
print("testing path protection")
|
||||
check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu")
|
||||
check_protect({ "eu ", "~diego" }, "eu%20/~diego")
|
||||
check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f")
|
||||
check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60")
|
||||
check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f")
|
||||
check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F")
|
||||
check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60")
|
||||
check_protect({ "{eu}", "|diego\127" }, "%7Beu%7D/%7Cdiego%7F")
|
||||
check_protect({ "eu ", "~diego" }, "eu /~diego", 1)
|
||||
check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1)
|
||||
check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1)
|
||||
|
Loading…
Reference in New Issue
Block a user