#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
package RT::URI;
use strict;
+use warnings;
use base 'RT::Base';
use RT::URI::base;
return ($self);
}
+=head2 CanonicalizeURI <URI>
+Returns the canonical form of the given URI by calling L</FromURI> and then L</URI>.
+
+If the URI is unparseable by FromURI the passed in URI is simply returned untouched.
+
+=cut
+
+sub CanonicalizeURI {
+ my $self = shift;
+ my $uri = shift;
+ if ($self->FromURI($uri)) {
+ my $canonical = $self->URI;
+ if ($canonical and $uri ne $canonical) {
+ RT->Logger->debug("Canonicalizing URI '$uri' to '$canonical'");
+ $uri = $canonical;
+ }
+ }
+ return $uri;
+}
-# {{{ FromObject
=head2 FromObject <Object>
-Given a local object, such as an RT::Ticket or an RT::FM::Article, this routine will return a URI for
+Given a local object, such as an RT::Ticket or an RT::Article, this routine will return a URI for
the local object
=cut
return $self->FromURI($obj->URI);
}
-# }}}
-# {{{ FromURI
=head2 FromURI <URI>
# Special case: integers passed in as URIs must be ticket ids
if ($uri =~ /^(\d+)$/) {
$scheme = "fsck.com-rt";
- } elsif ($uri =~ /^((?:\w|\.|-)+?):/) {
+ } elsif ($uri =~ /^((?!javascript|data)(?:\w|\.|-)+?):/i) {
$scheme = $1;
}
else {
+ $self->{resolver} = RT::URI::base->new( $self->CurrentUser ); # clear resolver
$RT::Logger->warning("Could not determine a URI scheme for $uri");
return (undef);
}
}
-# }}}
-# {{{ _GetResolver
=head2 _GetResolver <scheme>
if ($resolver) {
$self->{'resolver'} = $resolver;
} else {
+ RT->Logger->warning("Failed to create new resolver object for scheme '$scheme': $@")
+ if $@ !~ m{Can't locate RT/URI/\Q$scheme\E};
$self->{'resolver'} = RT::URI::base->new($self->CurrentUser);
}
}
-# }}}
-# {{{ Scheme
=head2 Scheme
return ($self->Resolver->Scheme);
}
-# }}}
-# {{{ URI
=head2 URI
return ($self->Resolver->URI);
}
-# }}}
-# {{{ Object
=head2 Object
}
-# }}}
-# {{{ IsLocal
=head2 IsLocal
}
-# }}}
=head2 AsHREF