diff options
-rw-r--r-- | src/url.lua | 10 | ||||
-rw-r--r-- | test/urltest.lua | 75 |
2 files changed, 77 insertions, 8 deletions
diff --git a/src/url.lua b/src/url.lua index 6448853..110ea94 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -139,16 +139,16 @@ function _M.parse(url, default) | |||
139 | parsed.authority = n | 139 | parsed.authority = n |
140 | return "" | 140 | return "" |
141 | end) | 141 | end) |
142 | -- get query string | ||
143 | url = string.gsub(url, "%?(.*)", function(q) | ||
144 | parsed.query = q | ||
145 | return "" | ||
146 | end) | ||
147 | -- get fragment | 142 | -- get fragment |
148 | url = string.gsub(url, "#(.*)$", function(f) | 143 | url = string.gsub(url, "#(.*)$", function(f) |
149 | parsed.fragment = f | 144 | parsed.fragment = f |
150 | return "" | 145 | return "" |
151 | end) | 146 | end) |
147 | -- get query string | ||
148 | url = string.gsub(url, "%?(.*)", function(q) | ||
149 | parsed.query = q | ||
150 | return "" | ||
151 | end) | ||
152 | -- get params | 152 | -- get params |
153 | url = string.gsub(url, "%;(.*)", function(p) | 153 | url = string.gsub(url, "%;(.*)", function(p) |
154 | parsed.params = p | 154 | parsed.params = p |
diff --git a/test/urltest.lua b/test/urltest.lua index 32cb348..1090a7e 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -91,6 +91,75 @@ end | |||
91 | 91 | ||
92 | print("testing URL parsing") | 92 | print("testing URL parsing") |
93 | check_parse_url{ | 93 | check_parse_url{ |
94 | url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment", | ||
95 | scheme = "scheme", | ||
96 | authority = "user:pass$%?#wd@host:port", | ||
97 | host = "host", | ||
98 | port = "port", | ||
99 | userinfo = "user:pass$%?#wd", | ||
100 | password = "pass$%?#wd", | ||
101 | user = "user", | ||
102 | path = "/path", | ||
103 | params = "params", | ||
104 | query = "query", | ||
105 | fragment = "fragment" | ||
106 | } | ||
107 | check_parse_url{ | ||
108 | url = "scheme://user:pass?#wd@host:port/path;params?query#fragment", | ||
109 | scheme = "scheme", | ||
110 | authority = "user:pass?#wd@host:port", | ||
111 | host = "host", | ||
112 | port = "port", | ||
113 | userinfo = "user:pass?#wd", | ||
114 | password = "pass?#wd", | ||
115 | user = "user", | ||
116 | path = "/path", | ||
117 | params = "params", | ||
118 | query = "query", | ||
119 | fragment = "fragment" | ||
120 | } | ||
121 | check_parse_url{ | ||
122 | url = "scheme://user:pass-wd@host:port/path;params?query#fragment", | ||
123 | scheme = "scheme", | ||
124 | authority = "user:pass-wd@host:port", | ||
125 | host = "host", | ||
126 | port = "port", | ||
127 | userinfo = "user:pass-wd", | ||
128 | password = "pass-wd", | ||
129 | user = "user", | ||
130 | path = "/path", | ||
131 | params = "params", | ||
132 | query = "query", | ||
133 | fragment = "fragment" | ||
134 | } | ||
135 | check_parse_url{ | ||
136 | url = "scheme://user:pass#wd@host:port/path;params?query#fragment", | ||
137 | scheme = "scheme", | ||
138 | authority = "user:pass#wd@host:port", | ||
139 | host = "host", | ||
140 | port = "port", | ||
141 | userinfo = "user:pass#wd", | ||
142 | password = "pass#wd", | ||
143 | user = "user", | ||
144 | path = "/path", | ||
145 | params = "params", | ||
146 | query = "query", | ||
147 | fragment = "fragment" | ||
148 | } | ||
149 | check_parse_url{ | ||
150 | url = "scheme://user:pass#wd@host:port/path;params?query", | ||
151 | scheme = "scheme", | ||
152 | authority = "user:pass#wd@host:port", | ||
153 | host = "host", | ||
154 | port = "port", | ||
155 | userinfo = "user:pass#wd", | ||
156 | password = "pass#wd", | ||
157 | user = "user", | ||
158 | path = "/path", | ||
159 | params = "params", | ||
160 | query = "query", | ||
161 | } | ||
162 | check_parse_url{ | ||
94 | url = "scheme://userinfo@host:port/path;params?query#fragment", | 163 | url = "scheme://userinfo@host:port/path;params?query#fragment", |
95 | scheme = "scheme", | 164 | scheme = "scheme", |
96 | authority = "userinfo@host:port", | 165 | authority = "userinfo@host:port", |
@@ -608,9 +677,9 @@ check_parse_path("eu/tu", { "eu", "tu" }) | |||
608 | print("testing path protection") | 677 | print("testing path protection") |
609 | check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") | 678 | check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") |
610 | check_protect({ "eu ", "~diego" }, "eu%20/~diego") | 679 | check_protect({ "eu ", "~diego" }, "eu%20/~diego") |
611 | check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") | 680 | check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F") |
612 | check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") | 681 | check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60") |
613 | check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") | 682 | check_protect({ "{eu}", "|diego\127" }, "%7Beu%7D/%7Cdiego%7F") |
614 | check_protect({ "eu ", "~diego" }, "eu /~diego", 1) | 683 | check_protect({ "eu ", "~diego" }, "eu /~diego", 1) |
615 | check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) | 684 | check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) |
616 | check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) | 685 | check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) |