-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
Description
In URI version 5.10, if a file name is provided that has leading and or trailing spaces, those will be removed since URI::file::Base::new()
calls URI->new
to generate the object, and URI
explicitly states it removes leading and trailing spaces.
See code below as an example:
#!/usr/local/bin/perl
use URI::file;
use File::Spec;
use v5.16;
my $file = ' some file ';
my $u = URI::file->new_abs( $file );
say "file path is: '$u'";
my @dirs = File::Spec->splitdir( $u->file( 'Unix' ) );
say $dirs[-1] eq $file ? 'ok' : ( "not ok: '" . $dirs[-1] . "', expected '$file'" );
exit(0);
__END__
This will yield something like:
file path is: 'file:///home/joe/some%20file'
not ok: 'some file', expected ' some file '
whereas, it should return: file:///home/joe/%20some%20file%20
and $u->file
should return ' some file '
The mitigation is to set back the path after the object has been instantiated, such as:
use URI::file;
use Cwd;
my $file = ' some file ';
my $u2 = URI::file->new( $file );
$u2->path( $file );
$u2 = $u2->abs( Cwd::cwd );
say "'" . $u2->file( 'Unix' ) . "'";
which would correctly yield '/home/joe/ some file '