Skip to content

Commit

Permalink
Merge pull request sartak#15 from tsibley/ssh-special-characters
Browse files Browse the repository at this point in the history
Handle special characters in filenames under the SSH service
  • Loading branch information
sartak committed Aug 30, 2011
2 parents 8bdf97b + 19a9683 commit 531f3ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -14,6 +14,7 @@ requires 'Module::Pluggable';
requires 'Moose' => '0.74';
requires 'MooseX::Getopt' => '0.17';
requires 'Class::Load';
requires 'URI::Escape';

features(
'pastebin.com support' => [
Expand Down
8 changes: 7 additions & 1 deletion lib/App/Nopaste/Service/ssh.pm
Expand Up @@ -5,6 +5,7 @@ use base 'App::Nopaste::Service';
use File::Temp;
use File::Spec;
use POSIX qw(strftime);
use URI::Escape qw(uri_escape);

sub run {
my ($self, %args) = @_;
Expand All @@ -28,15 +29,17 @@ sub run {
my ($vol, $dirs, $file) = File::Spec->splitpath($source);
$args{'desc'} = $file || '';
}
$args{'desc'} =~ s/\s+/+/g; # more readable than %20
$suffix = ($args{'desc'} ? '-' : '') . $args{'desc'} . $suffix;
}

my $tmp = File::Temp->new(
TEMPLATE => "${date}XXXXXXXX",
SUFFIX => $suffix,
UNLINK => 1,
TMPDIR => 1,
);
my $filename = $tmp->filename;
my $filename = File::Spec->rel2abs($tmp->filename);

print $tmp $args{text}
or return (0, "Can't write to tempfile $filename");
Expand All @@ -49,6 +52,9 @@ sub run {
system('scp', '-pq', $filename, "$server:$docroot");

my ($volume, $dir, $file) = File::Spec->splitpath($filename);
$file = uri_escape($file);
$file =~ s/%2b/+/gi;

return (1, "$topurl/$file");
}

Expand Down

0 comments on commit 531f3ce

Please sign in to comment.