[tpm] normalizing filespec paths/directories?

J. Bobby Lopez jbl at jbldata.com
Wed Jul 15 08:19:16 PDT 2009


If you wanted to roll your own, something like this may work:

#~~~~~~~~~~~~~~~~~~~
use strict;
use warnings;

sub testdir
{
    my $path = shift;
    my $testit = 1;
    my @dirs = split ('/', $path);
    my $goodir = '';
    foreach my $dir (@dirs)
    {
        if ( $dir =~ m{\.\.} && $testit eq 1 )
        {
            next;
        }
        $testit = 0;
        $goodir .= '/' . $dir;
    }

    if ( -f $goodir )
    {
        return $goodir;
    }
    else
    {
        return "dir not exist";
    }
}

my $path = "../../etc/passwd";
my $isgood = testdir($path);
print $isgood . "\n";
#~~~~~~~~~~~~~~~~~~~

On Wed, Jul 15, 2009 at 11:01 AM, Fulko Hew <fulko.hew at gmail.com> wrote:

>
>
> On Wed, Jul 15, 2009 at 10:51 AM, Dave Doyle <dave.s.doyle at gmail.com>wrote:
>
>> although I haven't tested:
>>
>> use Cwd;
>>
>> my $real_path = abs_path('/home/production/../../etc/password');
>>
>> I THINK it resolves symbolic links to the real path as well but you'd have
>> to check that.
>
>
> Thanks.  I just found it myself too.
> This is exactly what I needed.
>
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>


-- 
J. Bobby Lopez
Web: http://jbldata.com/
Twitter: http://www.twitter.com/jbobbylopez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090715/26580493/attachment.html>


More information about the toronto-pm mailing list