mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-08 14:28:21 +01:00
fixed url parsing; postpone fragment parsing after authority parsing; added test cases to test/urltest.lua
fixed reference patterns in check_protect() to upper case hex letters
This commit is contained in:
parent
3ee89515a0
commit
2d6a0f7bda
10
src/url.lua
10
src/url.lua
@ -139,16 +139,16 @@ function _M.parse(url, default)
|
||||
parsed.authority = n
|
||||
return ""
|
||||
end)
|
||||
-- get query string
|
||||
url = string.gsub(url, "%?(.*)", function(q)
|
||||
parsed.query = q
|
||||
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
|
||||
return ""
|
||||
end)
|
||||
-- get params
|
||||
url = string.gsub(url, "%;(.*)", function(p)
|
||||
parsed.params = p
|
||||
|
@ -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