diff options
Diffstat (limited to 'src/url.lua')
-rw-r--r-- | src/url.lua | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/url.lua b/src/url.lua index 1e59771..1bfecad 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- URI parsing, composition and relative URL resolution | 2 | -- URI parsing, composition and relative URL resolution |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id: url.lua,v 1.38 2006/04/03 04:45:42 diego Exp $ | ||
6 | ----------------------------------------------------------------------------- | 5 | ----------------------------------------------------------------------------- |
7 | 6 | ||
8 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
@@ -16,7 +15,7 @@ module("socket.url") | |||
16 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
17 | -- Module version | 16 | -- Module version |
18 | ----------------------------------------------------------------------------- | 17 | ----------------------------------------------------------------------------- |
19 | _VERSION = "URL 1.0.1" | 18 | _VERSION = "URL 1.0.2" |
20 | 19 | ||
21 | ----------------------------------------------------------------------------- | 20 | ----------------------------------------------------------------------------- |
22 | -- Encodes a string into its escaped hexadecimal representation | 21 | -- Encodes a string into its escaped hexadecimal representation |
@@ -142,7 +141,7 @@ function parse(url, default) | |||
142 | parsed.authority = n | 141 | parsed.authority = n |
143 | return "" | 142 | return "" |
144 | end) | 143 | end) |
145 | -- get query stringing | 144 | -- get query string |
146 | url = string.gsub(url, "%?(.*)", function(q) | 145 | url = string.gsub(url, "%?(.*)", function(q) |
147 | parsed.query = q | 146 | parsed.query = q |
148 | return "" | 147 | return "" |
@@ -158,9 +157,12 @@ function parse(url, default) | |||
158 | if not authority then return parsed end | 157 | if not authority then return parsed end |
159 | authority = string.gsub(authority,"^([^@]*)@", | 158 | authority = string.gsub(authority,"^([^@]*)@", |
160 | function(u) parsed.userinfo = u; return "" end) | 159 | function(u) parsed.userinfo = u; return "" end) |
161 | authority = string.gsub(authority, ":([^:]*)$", | 160 | authority = string.gsub(authority, ":([^:%]]*)$", |
162 | function(p) parsed.port = p; return "" end) | 161 | function(p) parsed.port = p; return "" end) |
163 | if authority ~= "" then parsed.host = authority end | 162 | if authority ~= "" then |
163 | -- IPv6? | ||
164 | parsed.host = string.match(authority, "^%[(.+)%]$") or authority | ||
165 | end | ||
164 | local userinfo = parsed.userinfo | 166 | local userinfo = parsed.userinfo |
165 | if not userinfo then return parsed end | 167 | if not userinfo then return parsed end |
166 | userinfo = string.gsub(userinfo, ":([^:]*)$", | 168 | userinfo = string.gsub(userinfo, ":([^:]*)$", |
@@ -185,6 +187,9 @@ function build(parsed) | |||
185 | local authority = parsed.authority | 187 | local authority = parsed.authority |
186 | if parsed.host then | 188 | if parsed.host then |
187 | authority = parsed.host | 189 | authority = parsed.host |
190 | if string.find(authority, ":") then -- IPv6? | ||
191 | authority = "[" .. authority .. "]" | ||
192 | end | ||
188 | if parsed.port then authority = authority .. ":" .. parsed.port end | 193 | if parsed.port then authority = authority .. ":" .. parsed.port end |
189 | local userinfo = parsed.userinfo | 194 | local userinfo = parsed.userinfo |
190 | if parsed.user then | 195 | if parsed.user then |