develooper Front page | perl.libwww | Postings from January 2002

Re: LWP and different ports

Thread Previous | Thread Next
From:
Gisle Aas
Date:
January 16, 2002 15:37
Subject:
Re: LWP and different ports
Message ID:
lr8zaxyikw.fsf@caliper.activestate.com
Daniel Harrison <danielh@loudcloud.com> writes:

>    use URI::Heuristic;
>    my $raw_url = "$target:$port/whatever.html";
>    my $url = URI::Heuristic::uf_urlstr($raw_url);

[...]

> It no longer worked. I added a line to print out the value of $raw_url
> and it was in the correct format - (192.168.11.122:8000/whatever.html)
> 
> Any suggestions?

Try this patch:

Index: URI/Heuristic.pm
===================================================================
RCS file: /cvsroot/libwww-perl/uri/URI/Heuristic.pm,v
retrieving revision 4.12
retrieving revision 4.13
diff -u -p -u -r4.12 -r4.13
--- URI/Heuristic.pm	2001/01/09 20:44:54	4.12
+++ URI/Heuristic.pm	2002/01/16 23:26:09	4.13
@@ -144,7 +144,7 @@ sub uf_uristr ($)
     } elsif (/^\w+([\.\-]\w+)*\@(\w+\.)+\w{2,3}$/) {
 	$_ = "mailto:$_";
 
-    } elsif (!/^[.+\-\w]+:/) {      # no scheme specified
+    } elsif (!/^[a-zA-Z][a-zA-Z0-9.+\-]*:/) {      # no scheme specified
 	if (s/^([-\w]+(?:\.[-\w]+)*)([\/:\?\#]|$)/$2/) {
 	    my $host = $1;
 
But you still get trouble if you use a real hostname instead of IP
adresses because "." are legal in URI scheme names.

    "foo.bar.com:8000/..."

will be treated as if belonged to the "foo.bar.com" scheme.  I guess
we could add another rule that says that if the thing right after ":"
is a number and the thing before resolve as a host name then prefix it
with "http://".

It is better to just use real URIs instead of going through
URI::Heuristic.

Regards,
Gisle

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About