X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRT%2FURI.pm;h=30a096de1866e286d40c72bc51690b88ae01ddbc;hp=4af1cb0da6eeaee9575e14cb18ebe0cb92a32199;hb=f2731f7f3883905cd17633f486d2aeb9593173da;hpb=43a06151e47d2c59b833cbd8c26d97865ee850b6 diff --git a/rt/lib/RT/URI.pm b/rt/lib/RT/URI.pm index 4af1cb0da..30a096de1 100644 --- a/rt/lib/RT/URI.pm +++ b/rt/lib/RT/URI.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -91,7 +91,26 @@ 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; +} =head2 FromObject @@ -122,33 +141,33 @@ 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); @@ -180,6 +199,8 @@ 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); } @@ -266,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;