Skip to content

Commit

Permalink
Display an error message when submitting executable (Fixes #257)
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianSalamander committed May 19, 2024
1 parent 51571c5 commit 320245e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ def submit
@problem = Problem.find(params[:id])
@submission = Submission.new(submit_params) # create submission
respond_to do |format|
if @submission.save
source_is_valid = @submission.source.valid_encoding? && !@submission.source.include?("\0")
if !source_is_valid
@submission.errors.add :source_file, "- Submission has an invalid text encoding. This was likely caused by submitting a compiled file (.exe, .out, .class, ...) instead of a source code file (.cpp, .c, .java, ...)."
@submission.source = nil; # Prevent submission form from trying to render the source (and erroring)
end

if source_is_valid && @submission.save
@submission.judge
format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') }
format.xml { render :xml => @submission, :status => :created, :location => @submission }
Expand Down

0 comments on commit 320245e

Please sign in to comment.