Skip to content

Commit

Permalink
Sanitize the filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwelch committed Apr 28, 2015
1 parent c5fff84 commit f02c85d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/controllers/deployment_targets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def destroy
def token
target = DeploymentTarget.find(params[:id])
send_data target.auth_blob,
filename: "#{target.name}.txt",
filename: "#{sanitize_filename(target.name)}.txt",
type: 'text/plain'
end

private

def sanitize_filename(name)
name.gsub!(/[^0-9A-Za-z.\-]/, '_')
end

def hydrate_index_view
@deployment_targets = DeploymentTarget.all
@job_templates_by_vendor = JobTemplate.all.group_by(&:vendor)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/deployment_targets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
end

describe 'GET #token' do
let(:fake_target) { double(:fake_target, auth_blob: 'blob', name: 'pro') }
let(:fake_target) { double(:fake_target, auth_blob: 'blob', name: 'prod! targ^0') }
before do
allow(DeploymentTarget).to receive(:find).with('7').and_return(fake_target)
end

it 'sends a file of the token' do
expect(controller).to receive(:send_data).with(
'blob',
filename: 'pro.txt',
filename: 'prod__targ_0.txt',
type: 'text/plain'
)
get :token, id: 7
Expand Down

0 comments on commit f02c85d

Please sign in to comment.