From 1bc3324eac311d0487135d1a70a06c281deb86b5 Mon Sep 17 00:00:00 2001 From: Martijn Versluis Date: Fri, 9 Aug 2019 10:13:08 +0200 Subject: [PATCH] Support file paths with spaces for RETR command Because the FTP command is splitted by spaces, file paths with spaces are not supported, because the Retr command only uses the first part of the path until the first space. This change ensures all parts are used. --- lib/fake_ftp/server_commands/retr.rb | 3 ++- spec/functional/server_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/fake_ftp/server_commands/retr.rb b/lib/fake_ftp/server_commands/retr.rb index 733535c..41a909e 100644 --- a/lib/fake_ftp/server_commands/retr.rb +++ b/lib/fake_ftp/server_commands/retr.rb @@ -3,7 +3,8 @@ module FakeFtp module ServerCommands class Retr - def run(ctx, filename = '', *) + def run(ctx, *filename_parts) + filename = filename_parts.join(' ') ctx.respond_with('501 No filename given') if filename.empty? f = ctx.file(filename.to_s) diff --git a/spec/functional/server_spec.rb b/spec/functional/server_spec.rb index b28bf97..e55bc13 100644 --- a/spec/functional/server_spec.rb +++ b/spec/functional/server_spec.rb @@ -298,6 +298,18 @@ .to eql("226 File transferred\r\n") end + it 'accepts RETR with a filepath containing spaces' do + server.add_file(file_prefix + 'some dir/some file', '1234567890') + client.write("RETR #{file_prefix}some dir/some file\r\n") + expect(SpecHelper.gets_with_timeout(client)) + .to eql("150 File status ok, about to open data connection\r\n") + data = SpecHelper.gets_with_timeout(data_client, endwith: "\0") + data_client.close + expect(data).to eql('1234567890') + expect(SpecHelper.gets_with_timeout(client)) + .to eql("226 File transferred\r\n") + end + it 'accepts DELE with a filename' do server.add_file('some_file', '1234567890') client.write("DELE some_file\r\n")