Skip Menu |
 

This queue is for tickets about the URI CPAN distribution.

Report information
The Basics
Id: 69035
Status: open
Priority: 0/
Queue: URI

People
Owner: Nobody in particular
Requestors: fulko.hew [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: trouble parsing a URI example from wikipedia
Date: Wed, 22 Jun 2011 15:54:44 -0400
To: bug-URI [...] rt.cpan.org
From: Fulko Hew <fulko.hew [...] gmail.com>
Download (untitled) / with headers
text/plain 749b
I thought I'd try to use URI.pm in my code, and when I tested it with an example I saw in Wikipedia, it didn't work right. Therefore I don't know if Wikipedia is incorrect, URI.pm has a bug or URI.pm has a limitation. The URI I was testing against was from: http://en.wikipedia.org/wiki/URI_scheme with the actual text of: foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose So my test code was: perl -e 'use URI; $u=URI->new("foo://username:password@example.com:8000/over/there/index.dtb?type=animal&name=narwhal#nose"); print $u->host, "\n";' expecting to see 'example.com' emitted, but I see 'username:password.com' instead. I also tried printing 'userinfo', but that also didn't decode correctly.
Download (untitled) / with headers
text/plain 1.1k
On Wed Jun 22 15:55:15 2011, fulko.hew@gmail.com wrote: Show quoted text
> I thought I'd try to use URI.pm in my code, and when I tested it > with an example I saw in Wikipedia, it didn't work right. > Therefore I don't know if Wikipedia is incorrect, URI.pm has a > bug or URI.pm has a limitation. > > The URI I was testing against was from: > > http://en.wikipedia.org/wiki/URI_scheme > > with the actual text of: > > foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose > > So my test code was: > > perl -e 'use URI; > $u=URI-
> >new("foo://username:password@example.com:8000/over/there/index.dtb?type=animal&name=narwhal#nose");
> print $u->host, "\n";'
When I try this I see: Can't locate object method "host" via package "URI::_foreign" at -e line 3. and if I add -w to the options I see: Possible unintended interpolation of @example in string at -e line 2. Isn't the missing perl-level escape of \@ your problem? Show quoted text
> > expecting to see 'example.com' emitted, but I see > 'username:password.com' instead. > > I also tried printing 'userinfo', but that also didn't decode > correctly.
Subject: Re: [rt.cpan.org #69035] trouble parsing a URI example from wikipedia
Date: Mon, 15 Aug 2011 10:54:41 -0400
To: bug-URI [...] rt.cpan.org
From: Fulko Hew <fulko.hew [...] gmail.com>
Download (untitled) / with headers
text/plain 1.9k
On Sun, Aug 14, 2011 at 3:21 AM, Gisle_Aas via RT <bug-URI@rt.cpan.org>wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=69035 > > > On Wed Jun 22 15:55:15 2011, fulko.hew@gmail.com wrote:
> > I thought I'd try to use URI.pm in my code, and when I tested it > > with an example I saw in Wikipedia, it didn't work right. > > Therefore I don't know if Wikipedia is incorrect, URI.pm has a > > bug or URI.pm has a limitation. > > > > The URI I was testing against was from: > > > > http://en.wikipedia.org/wiki/URI_scheme > > > > with the actual text of: > > > > foo://
> username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose
> > > > So my test code was: > > > > perl -e 'use URI; > > $u=URI-
> > >new("foo://
> username:password@example.com:8000/over/there/index.dtb?type=animal&name=narwhal#nose > ");
> > print $u->host, "\n";'
> > When I try this I see: > > Can't locate object method "host" via package "URI::_foreign" at -e line > 3. > > and if I add -w to the options I see: > > Possible unintended interpolation of @example in string at -e line 2. > > Isn't the missing perl-level escape of \@ your problem? >
Thanks for pointing out the missing escape, but that isn't the real problem. Following your response, I did a little more testing... It turns out that because the example used a schema of 'foo:', the URI.pm did not 'know' how to decode this and therefore generated the "can't locate method 'host'" error/warning. When I changed the schema to something like 'http', it successfully finds the host() method and returns a correct value (...provided I escape the @). Is this the expected behavior when there is an 'unknown' schema? Does URI.pm only support 'known' schemas? Thanks for your assistance. Fulko Show quoted text
>
> > expecting to see 'example.com' emitted, but I see > > 'username:password.com' instead. > > > > I also tried printing 'userinfo', but that also didn't decode > > correctly.
> > > >
Download (untitled) / with headers
text/plain 692b
The URI documentation for GENERIC METHODS states that "Unknown schemes are assumed to support the generic syntax, and therefore the following methods". So, for the unknown "foo" scheme the generic methods like path, query etc are available. You seem to also want the SERVER METHODS. To get at those you can do one of the following: * Create 'package URI::foo' and make it subclass URI::_server and then define the default_port method within that class. Now "foo" URLs also has methods like host, port, userinfo. * push(@URI::_foreign::ISA, "URI::_server") for global effect on all unknown schemes. I think URI does the right thing in not providing SERVER methods to unknown schemes.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.