Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Relative URI

by Anonymous Monk
on Apr 21, 2011 at 23:48 UTC ( #900738=note: print w/ replies, xml ) Need Help??


in reply to Relative URI

I don't get it, what is it you're expecting? Try

use Test::More qw' no_plan '; ... is( $uri->rel($base), ' expect ' );
Have you seen/run http://cpansearch.perl.org/src/GAAS/URI-1.58/t/abs.t?


Comment on Re: Relative URI
Download Code
Re^2: Relative URI
by ikegami (Pope) on Apr 21, 2011 at 23:58 UTC

    He expects http://a.b.c/d/../e/ to be the same as http://a.b.c/e/.

    use strict; use warnings; use Test::More tests => 1; use URI qw( ); my $base1 = URI->new("http://a.b.c/d/../e/"); my $base2 = URI->new_abs("../e/", URI->new("http://a.b.c/d/")); my $uri = URI->new("http://a.b.c/y"); is($uri->rel($base1), $uri->rel($base2)); 1;
    1..1 not ok 1 # Failed test at a.pl line 12. # got: '../../../y' # expected: '../y' # Looks like you failed 1 test of 1.

    I don't see anything in http://cpansearch.perl.org/src/GAAS/URI-1.58/t/abs.t that covers this case.

    The equality definitely doesn't hold up in file systems (due to links both soft and hard), but ../../../y is much less likely to be correct.

    Update: Improved test a bit.

      He expects http://a.b.c/d/../e/ to be the same as http://a.b.c/e/.
      If I read section 5.2 of RFC 3986 correctly, the OP quite rightly expects that to be.

        5.2 describes how to make an absolute uri from a (possibly) relative URL.

        In that context, "/d/../e/" is equivalent to "/e/", but the module already does that correctly.

        Update: 6.2.2.3 seems more relevant here.

        There is a violation of 5.2 elsewhere, though.

        use strict; use warnings; use Test::More tests => 1; use URI qw( ); # if defined(R.scheme) then # T.scheme = R.scheme; # T.authority = R.authority; # T.path = remove_dot_segments(R.path); # T.query = R.query; is( URI->new_abs('http://a.b.c/d/../e/', 'http://a.b.c/'), 'http://a.b +.c/e/' ); 1;
        1..1 not ok 1 # Failed test at a.pl line 8. # got: 'http://a.b.c/d/../e/' # expected: 'http://a.b.c/e/' # Looks like you failed 1 test of 1.

        I would except cannonical to implement 6.2.2.3. It does implement other similar rules.

        use strict; use warnings; use Test::More tests => 6; use URI qw( ); is( URI->new('hTtP://a.b.c/' )->canonical, 'http://a.b.c/', 'R +FC 3986, 6.2.2.1' ); is( URI->new('http://a.b.c/d/../e/')->canonical, 'http://a.b.c/e/', 'R +FC 3986, 6.2.2.3' ); is( URI->new('http://a.b.c' )->canonical, 'http://a.b.c/', 'R +FC 3986, 6.2.3' ); is( URI->new('http://a.b.c:' )->canonical, 'http://a.b.c/', 'R +FC 3986, 6.2.3' ); is( URI->new('http://a.b.c:/' )->canonical, 'http://a.b.c/', 'R +FC 3986, 6.2.3' ); is( URI->new('http://a.b.c:80/' )->canonical, 'http://a.b.c/', 'R +FC 3986, 6.2.3' ); 1;
        1..6 ok 1 - RFC 3986, 6.2.2.1 not ok 2 - RFC 3986, 6.2.2.3 # Failed test 'RFC 3986, 6.2.2.3' # at a.pl line 10. # got: 'http://a.b.c/d/../e/' # expected: 'http://a.b.c/e/' ok 3 - RFC 3986, 6.2.3 ok 4 - RFC 3986, 6.2.3 ok 5 - RFC 3986, 6.2.3 ok 6 - RFC 3986, 6.2.3 # Looks like you failed 1 test of 6.
Re^2: Relative URI
by Anonymous Monk on Apr 22, 2011 at 00:05 UTC
    #!/usr/bin/perl -- use strict; use warnings; use URI; Main( @ARGV ); exit( 0 ); sub Main { ABT(); } sub ABT { require Test::More; Test::More->import(qw' no_plan '); my $base = URI->new("http://a/d/../e/"); my $uri = URI->new("http://a/y"); is( $base, ( "http://a/d/../e/" ) x 2 ); is( $base->path, ( "/d/../e/" ) x 2 ); is( $uri, ( "http://a/y" ) x 2 ); is( $uri->path, ( "/y" ) x 2 ); diag("should the following be equivalent??"); is( $uri->rel($base), "??", q~$uri->rel($base)~ ); is( URI->new( $uri->path )->rel( $base->path ), $uri->rel($base), q~URI->new( $uri->path )->rel( $base->path ) +~ ); is( URI->new("/y")->rel("/d/../e/"), $uri->rel($base), q~URI->new("/y")->rel("/d/../e/") ~ ); } __END__ ok 1 - http://a/d/../e/ ok 2 - /d/../e/ ok 3 - http://a/y ok 4 - /y # should the following be equivalent?? not ok 5 - $uri->rel($base) # Failed test '$uri->rel($base)' # at - line 27. # got: '../../../y' # expected: '??' not ok 6 - URI->new( $uri->path )->rel( $base->path ) # Failed test 'URI->new( $uri->path )->rel( $base->path )' # at - line 28. # got: '/y' # expected: '../../../y' not ok 7 - URI->new("/y")->rel("/d/../e/") # Failed test 'URI->new("/y")->rel("/d/../e/") ' # at - line 30. # got: '/y' # expected: '../../../y' 1..7 # Looks like you failed 3 tests of 7.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://900738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-05 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls