X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FURI.pm;h=ba9c491e9bfd7370f8cb4e2bcff7ee5d38c2a5cd;hp=facce04133b1d573e5210bb47b4015e43451b615;hb=187086c479a09629b7d180eec513fb7657f4e291;hpb=75162bb14b3e38d66617077843f4dfdcaf09d5c4 diff --git a/rt/lib/RT/URI.pm b/rt/lib/RT/URI.pm index facce0413..ba9c491e9 100644 --- a/rt/lib/RT/URI.pm +++ b/rt/lib/RT/URI.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -49,6 +49,7 @@ package RT::URI; use strict; +use warnings; use base 'RT::Base'; use RT::URI::base; @@ -90,13 +91,31 @@ sub new { return ($self); } +=head2 CanonicalizeURI +Returns the canonical form of the given URI by calling L and then L. + +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 -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 @@ -109,9 +128,7 @@ sub FromObject { return $self->FromURI($obj->URI); } -# }}} -# {{{ FromURI =head2 FromURI @@ -124,41 +141,40 @@ Returns true if everything is ok, otherwise false sub FromURI { my $self = shift; - my $uri = shift; + my $uri = shift; return undef unless ($uri); my $scheme; # Special case: integers passed in as URIs must be ticket ids if ($uri =~ /^(\d+)$/) { - $scheme = "fsck.com-rt"; - } elsif ($uri =~ /^((?:\w|\.|-)+?):/) { - $scheme = $1; + $scheme = "fsck.com-rt"; + } 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); } - - # load up a resolver object for this scheme + + # load up a resolver object for this scheme $self->_GetResolver($scheme); - + unless ($self->Resolver->ParseURI($uri)) { $RT::Logger->warning( "Resolver " . ref( $self->Resolver ) . " could not parse $uri, maybe Organization config was changed?" ); $self->{resolver} = RT::URI::base->new( $self->CurrentUser ); # clear resolver - return (undef); + return (undef); } return(1); } -# }}} -# {{{ _GetResolver =head2 _GetResolver @@ -183,14 +199,14 @@ sub _GetResolver { 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 @@ -204,8 +220,6 @@ sub Scheme { return ($self->Resolver->Scheme); } -# }}} -# {{{ URI =head2 URI @@ -219,9 +233,7 @@ sub URI { return ($self->Resolver->URI); } -# }}} -# {{{ Object =head2 Object @@ -237,9 +249,7 @@ sub Object { } -# }}} -# {{{ IsLocal =head2 IsLocal @@ -253,7 +263,6 @@ sub IsLocal { } -# }}} =head2 AsHREF @@ -278,6 +287,17 @@ sub Resolver { return ($self->{'resolver'}); } +=head2 AsString + +Returns a friendly display form of the object if Local, or the full URI + +=cut + +sub AsString { + my $self = shift; + return $self->Resolver->AsString; +} + RT::Base->_ImportOverlays(); 1;