mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08: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
|
parsed.authority = n
|
||||||
return ""
|
return ""
|
||||||
end)
|
end)
|
||||||
-- get query string
|
|
||||||
url = string.gsub(url, "%?(.*)", function(q)
|
|
||||||
parsed.query = q
|
|
||||||
return ""
|
|
||||||
end)
|
|
||||||
-- get fragment
|
-- get fragment
|
||||||
url = string.gsub(url, "#(.*)$", function(f)
|
url = string.gsub(url, "#(.*)$", function(f)
|
||||||
parsed.fragment = f
|
parsed.fragment = f
|
||||||
return ""
|
return ""
|
||||||
end)
|
end)
|
||||||
|
-- get query string
|
||||||
|
url = string.gsub(url, "%?(.*)", function(q)
|
||||||
|
parsed.query = q
|
||||||
|
return ""
|
||||||
|
end)
|
||||||
-- get params
|
-- get params
|
||||||
url = string.gsub(url, "%;(.*)", function(p)
|
url = string.gsub(url, "%;(.*)", function(p)
|
||||||
parsed.params = p
|
parsed.params = p
|
||||||
|
@ -90,6 +90,75 @@ local check_parse_url = function(gaba)
|
|||||||
end
|
end
|
||||||
|
|
||||||
print("testing URL parsing")
|
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{
|
check_parse_url{
|
||||||
url = "scheme://userinfo@host:port/path;params?query#fragment",
|
url = "scheme://userinfo@host:port/path;params?query#fragment",
|
||||||
scheme = "scheme",
|
scheme = "scheme",
|
||||||
@ -608,9 +677,9 @@ check_parse_path("eu/tu", { "eu", "tu" })
|
|||||||
print("testing path protection")
|
print("testing path protection")
|
||||||
check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu")
|
check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu")
|
||||||
check_protect({ "eu ", "~diego" }, "eu%20/~diego")
|
check_protect({ "eu ", "~diego" }, "eu%20/~diego")
|
||||||
check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f")
|
check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F")
|
||||||
check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60")
|
check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60")
|
||||||
check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f")
|
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)
|
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