<?xml version="1.0" encoding="windows-1252"?>
<node id="900740" title="Re^2: Relative URI" created="2011-04-21 20:05:57" updated="2011-04-21 20:05:57">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;c&gt;
#!/usr/bin/perl --
use strict;
use warnings;
use URI;

Main( @ARGV );
exit( 0 );

sub Main {
    ABT();
}

sub ABT {
    require Test::More;
    Test::More-&gt;import(qw' no_plan ');

    my $base = URI-&gt;new("http://a/d/../e/");
    my $uri = URI-&gt;new("http://a/y");

    is( $base, ( "http://a/d/../e/" ) x 2 );
    is( $base-&gt;path, ( "/d/../e/" ) x 2 );
    is( $uri, ( "http://a/y" ) x 2 );
    is( $uri-&gt;path, ( "/y" ) x 2 );

    diag("should the following be equivalent??");

    is( $uri-&gt;rel($base), "??", q~$uri-&gt;rel($base)~ );
    is( URI-&gt;new( $uri-&gt;path )-&gt;rel( $base-&gt;path ),
        $uri-&gt;rel($base), q~URI-&gt;new( $uri-&gt;path )-&gt;rel( $base-&gt;path )~ );
    is( URI-&gt;new("/y")-&gt;rel("/d/../e/"),
        $uri-&gt;rel($base), q~URI-&gt;new("/y")-&gt;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-&gt;rel($base)
#   Failed test '$uri-&gt;rel($base)'
#   at - line 27.
#          got: '../../../y'
#     expected: '??'
not ok 6 - URI-&gt;new( $uri-&gt;path )-&gt;rel( $base-&gt;path )
#   Failed test 'URI-&gt;new( $uri-&gt;path )-&gt;rel( $base-&gt;path )'
#   at - line 28.
#          got: '/y'
#     expected: '../../../y'
not ok 7 - URI-&gt;new("/y")-&gt;rel("/d/../e/")
#   Failed test 'URI-&gt;new("/y")-&gt;rel("/d/../e/") '
#   at - line 30.
#          got: '/y'
#     expected: '../../../y'
1..7
# Looks like you failed 3 tests of 7.
&lt;/C&gt;</field>
<field name="root_node">
900729</field>
<field name="parent_node">
900738</field>
<field name="reputation">
3</field>
</data>
</node>
