Skip to content

Commit

Permalink
fix issue caused by malformed urls
Browse files Browse the repository at this point in the history
Entering a malformed URL would cause a submission draft failure. This
was because of an error that was raised during url validation that we
weren't handling correctly. Adding the appropriate rescue for errors on
validation fixes this issue.

Test Plan
- Create an assignment with an online_url submission type
- Navigate to the assignment as the student
- Enter a malformed url e.g. http:www.google.com
- The draft should be created but there should be a warning below the
  input stating that a valid url should be entered and there should be
  no submit button
- Enter a valid url and note that the draft should be saved and the
  submit button should be displayed.
- Enter a malformed url again and the draft should be saved and the
  submit button should disappear. There should also be a warning message
  about entering a valid url below the input.

fixes WOKE-40
fixes WOKE-41
flag=assignments_2_student

Change-Id: I64d017188e8e48cd9851139f2a7e1a7dfad63647
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215803
Tested-by: Jenkins
Reviewed-by: Steven Burnett <[email protected]>
QA-Review: Steven Burnett <[email protected]>
Product-Review: Steven Burnett <[email protected]>
  • Loading branch information
mlemon-instructure authored and sdb1228 committed Nov 5, 2019
1 parent 6b20cd9 commit ac6602c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/submission_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate_url
# otherwise leaves the url as whatever the user submitted as thier draft
value, = CanvasHttp.validate_url(self.url)
self.send("url=", value)
rescue URI::Error, ArgumentError
rescue
return
end
end
Expand Down Expand Up @@ -80,7 +80,7 @@ def meets_url_criteria?
begin
CanvasHttp.validate_url(self.url)
true
rescue URI::Error, ArgumentError
rescue
false
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/submission_draft_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
expect(@submission_draft.meets_assignment_criteria?).to eq(false)
end

it 'returns false if the url is malformed' do
@submission_draft.url = 'http:www.google.com'
expect(@submission_draft.meets_assignment_criteria?).to eq(false)
end

it 'returns false if the url is empty' do
@submission_draft.url = ''
expect(@submission_draft.meets_assignment_criteria?).to eq(false)
Expand Down

0 comments on commit ac6602c

Please sign in to comment.