Hi,

Attached patch (with test) fixes AnyEvent::HTTP's parsing of URLs so
that it accepts IPv6 literals.

Please let me know what you think.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net
Index: libanyevent-http-perl-2.21-1/HTTP.pm
===================================================================
--- libanyevent-http-perl-2.21-1/HTTP.pm
+++ libanyevent-http-perl-2.21-1/HTTP.pm
@@ -769,17 +769,28 @@
       $url =~ m|^([^:]+):(?://([^/?#]*))?([^?#]*)(?:(\?[^#]*))?(?:#(.*))?$|;
 
    $uscheme = lc $uscheme;
 
+   my $uhost;
    my $uport = $uscheme eq "http"  ?  80
              : $uscheme eq "https" ? 443
              : return $cb->(undef, { @pseudo, Status => 599, Reason => "Only http and https URL schemes supported" });
 
-   $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x
-      or return $cb->(undef, { @pseudo, Status => 599, Reason => "Unparsable URL" });
+   if ($uauthority =~ m/\[.+\]/) {
+      if ($uauthority =~ /^(?: .*\@ )? \[ ([:a-fA-F0-9\.]+) \] (?: : (\d+) )?$/x) {
+          $uhost = lc $1;
+          $uport = $2 if defined $2;
+      }
+   } else {
+      if ($uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x) {
+          $uhost = lc $1;
+          $uport = $2 if defined $2;
+      }
+   }
 
-   my $uhost = lc $1;
-   $uport = $2 if defined $2;
+   unless ($uhost) {
+      return $cb->(undef, { @pseudo, Status => 599, Reason => "Unparsable URL" });
+   }
 
    $hdr{host} = defined $2 ? "$uhost:$2" : "$uhost"
       unless exists $hdr{host};
 

Attachment: 02_ipv6.t
Description: Troff document

_______________________________________________
anyevent mailing list
anyevent@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/anyevent

Reply via email to