diff --git a/app/helpers/renderers/feedback_table_renderer.rb b/app/helpers/renderers/feedback_table_renderer.rb index fd3b877468..30e32bd4b3 100644 --- a/app/helpers/renderers/feedback_table_renderer.rb +++ b/app/helpers/renderers/feedback_table_renderer.rb @@ -319,17 +319,23 @@ def messages(msgs) end end - def differ(t) - if t[:format] == 'csv' && CsvDiffer.limited_columns?(t[:generated]) && CsvDiffer.limited_columns?(t[:expected]) - CsvDiffer - else - TextDiffer + def with_differ_class(t) + if t[:format] == 'csv' + begin + return yield(CsvDiffer) if CsvDiffer.limited_columns?(t[:generated]) && CsvDiffer.limited_columns?(t[:expected]) + rescue CSV::MalformedCSVError + # use the default differ + end end + + yield(TextDiffer) end def test_accepted(t) @builder.div(class: 'test-accepted') do - differ(t).render_accepted(@builder, t[:generated]) + with_differ_class(t) do |differ_class| + differ_class.render_accepted(@builder, t[:expected]) + end end end @@ -340,10 +346,12 @@ def test_failed(t) end def diff(t) - differ = differ(t).new(t[:generated], t[:expected]) - @builder.div(class: "diffs show-#{@diff_type}") do - @builder << differ.split - @builder << differ.unified + with_differ_class(t) do |differ_class| + differ = differ_class.new(t[:generated], t[:expected]) + @builder.div(class: "diffs show-#{@diff_type}") do + @builder << differ.split + @builder << differ.unified + end end end diff --git a/test/controllers/submissions_controller_test.rb b/test/controllers/submissions_controller_test.rb index de18639095..a362ac2e5b 100644 --- a/test/controllers/submissions_controller_test.rb +++ b/test/controllers/submissions_controller_test.rb @@ -477,4 +477,13 @@ def expected_score_string(*args) assert_response :ok end + + test 'Should be able to render submission with malformed csv' do + submission = create :wrong_submission, code: 'select * from track where trackid = 1610', + result: '{"accepted":false,"status":"wrong","description":"Test failed","annotations":[{"text":"An SQL query should end with a semicolon","type":"info","row":1,"rows":1,"column":null,"columns":null,"externalUrl":null}],"groups":[{"description":"Result Validation","badgeCount":2,"groups":[{"accepted":false,"groups":[{"description":"Compare results","accepted":false,"tests":[{"expected":"\"title\"\\n\"Grace\"\\n\"Monster\"\\n\"The Greatest Hits\"\\n\"Throwing Copper\"\\n\"Toward the Within\"\\n\"Troublegum\"\\n\"Worst Case Scenario\"","format":"csv","messages":[{"format":"callout-danger","description":"Incorrect row count"}],"generated":"\"title\",\"trackid\",\"genre\",\"albumid\",\"artistid\",\"tracknumber\"\\n\"\"So Fast, So Numb\"\",\"1610\",\"Rock\",\"523\",\"229\",\"12\"","accepted":false}]}]},{"accepted":true,"groups":[{"description":"Column Types","accepted":true,"tests":[{"expected":"\"column\",\"type\"\\n\"title\",\"STRING\"","format":"csv","generated":"\"column\",\"type\"\\n\"title\",\"STRING\"\\n\"trackid\",\"INTEGER\"\\n\"genre\",\"STRING\"\\n\"albumid\",\"INTEGER\"\\n\"artistid\",\"INTEGER\"\\n\"tracknumber\",\"INTEGER\"","accepted":true}]}]},{"accepted":false,"groups":[{"description":"Order By","accepted":false,"tests":[{"expected":"correct order","generated":"incorrect order","accepted":false}]}]}]},{"description":"Query Result","badgeCount":0,"groups":[{"accepted":true,"groups":[{"description":"Full result","accepted":true,"tests":[{"expected":"","format":"csv","generated":"\"title\",\"trackid\",\"genre\",\"albumid\",\"artistid\",\"tracknumber\"\\n\"\"So Fast, So Numb\"\",\"1610\",\"Rock\",\"523\",\"229\",\"12\"","accepted":true}]}]}]}],"messages":[{"format":"html","description":"\\u003cstrong\\u003eWorker:\\u003c/strong\\u003e ixion","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eMemory usage:\\u003c/strong\\u003e 40.61 MiB","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003ePrepare:\\u003c/strong\\u003e 0.13 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eRuntime:\\u003c/strong\\u003e 0.92 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eResult construction:\\u003c/strong\\u003e 0.02 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eFinalize:\\u003c/strong\\u003e 0.01 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eTotal time:\\u003c/strong\\u003e 1.14 seconds","permission":"zeus"}]}' + sign_in submission.user + get submission_path(submission) + + assert_response :ok + end end