httpclient: fix parsing of IPv6 URLs (#662)
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 5 Feb 2014 13:44:07 +0000 (13:44 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 5 Feb 2014 13:44:07 +0000 (13:44 +0000)
libs/httpclient/luasrc/httpclient.lua

index 93eed05c63d4f4c723fdca58b8740a43590efca0..c866be6855cc59dc1e7409dec42fa54e10a8db92 100644 (file)
@@ -108,11 +108,22 @@ end
 function request_raw(uri, options)
        options = options or {}
        local pr, auth, host, port, path
-       if uri:find("@") then
-               pr, auth, host, port, path =
-                       uri:match("(%w+)://(.+)@([%w-.]+):?([0-9]*)(.*)")
+       
+       if uri:find("%[") then
+               if uri:find("@") then
+                       pr, auth, host, port, path = uri:match("(%w+)://(.+)@(%b[]):?([0-9]*)(.*)")
+                       host = host:sub(2,-2)
+               else
+                       pr, host, port, path = uri:match("(%w+)://(%b[]):?([0-9]*)(.*)")
+                       host = host:sub(2,-2)
+               end
        else
-               pr, host, port, path = uri:match("(%w+)://([%w-.]+):?([0-9]*)(.*)")
+               if uri:find("@") then
+                       pr, auth, host, port, path =
+                               uri:match("(%w+)://(.+)@([%w-.]+):?([0-9]*)(.*)")
+               else
+                       pr, host, port, path = uri:match("(%w+)://([%w-.]+):?([0-9]*)(.*)")
+               end
        end
 
        if not host then