Skip to content
Snippets Groups Projects
Commit 35471113 authored by Miguel Cabeça's avatar Miguel Cabeça
Browse files

Refactored encoding of build output.

Moved the GitlabCi::Encode.encode! method call closer to the file read.
This keeps the boundary between "external file source with crazy
encoding -> internal rails code all in utf-8" well defined.
Additionally the build output file is opened in binary mode to prevent
encoding exceptions while reading it. It will be converted to utf-8 by
GitlabCi::Encode.encode!
parent 8846a197
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -73,8 +73,7 @@ class Build < ActiveRecord::Base
 
def write_trace(trace)
self.reload
sanitized_output = sanitize_build_output(trace)
update_attributes(trace: sanitized_output)
update_attributes(trace: trace)
end
 
def short_before_sha
Loading
Loading
@@ -86,22 +85,12 @@ class Build < ActiveRecord::Base
end
 
def trace_html
if trace.present?
Ansi2html::convert(compose_output)
else
''
end
end
def sanitize_build_output(output)
GitlabCi::Encode.encode!(output)
html = Ansi2html::convert(compose_output) if trace.present?
html ||= ''
end
 
def read_tmp_file
content = if tmp_file && File.readable?(tmp_file)
File.read(tmp_file)
end
content = GitlabCi::Encode.encode!(File.binread(tmp_file)) if tmp_file && File.readable?(tmp_file)
content ||= ''
end
 
Loading
Loading
@@ -109,8 +98,7 @@ class Build < ActiveRecord::Base
output = trace
 
if running?
sanitized_output = sanitize_build_output(read_tmp_file)
output << sanitized_output if sanitized_output.present?
output << read_tmp_file
end
 
output
Loading
Loading
Loading
Loading
@@ -75,7 +75,7 @@ class Runner
@output << "\n"
 
@process = ChildProcess.build(cmd)
@tmp_file = Tempfile.new("child-output")
@tmp_file = Tempfile.new("child-output", binmode: true)
@process.io.stdout = @tmp_file
@process.io.stderr = @tmp_file
@process.cwd = path
Loading
Loading
@@ -98,7 +98,9 @@ class Runner
@process.exit_code == 0
ensure
@tmp_file.rewind
@output << @tmp_file.read
@output << GitlabCi::Encode.encode!(@tmp_file.read)
@tmp_file.close
@tmp_file.unlink
end
 
def prepare_project_cmd(path, ref)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment