Skip to content

Commit

Permalink
Merge pull request #10349 from vpereira/parse_date_with_date_class
Browse files Browse the repository at this point in the history
Use Date.parse instead of Time.now.parse to parse user controlled date
  • Loading branch information
saraycp committed Oct 27, 2020
2 parents c559f51 + d3b5601 commit b9198de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def autoclean_project(prj)
attribute = prj.attribs.find_by_attrib_type_id(@cleanup_attribute.id)
return unless attribute

time = Time.zone.parse(attribute.values.first.value)
time = Date.parse(attribute.values.first.value)
rescue TypeError, ArgumentError
# nil time raises TypeError
return
Expand Down
18 changes: 18 additions & 0 deletions src/api/spec/jobs/project_create_auto_cleanup_requests_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,23 @@
expect(project.target_of_bs_request_actions.where(type: 'delete').count).to eq(0)
end
end

context 'with empty cleanup time' do
before do
attribute.values.first.value = ''
attribute.save
end

it { expect { subject }.not_to raise_error }
end

context 'with invalid cleanup time' do
before do
attribute.values.first.value = '200000'
attribute.save
end

it { expect { subject }.not_to raise_error }
end
end
end

0 comments on commit b9198de

Please sign in to comment.