Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Better encode #100

Merged
merged 2 commits into from

2 participants

@cabeca

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!

cabeca added some commits
@cabeca cabeca Removed initializer by moving require to encode lib where it belongs. 8846a19
@cabeca cabeca 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!
3547111
@randx randx merged commit ad65ca3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2013
  1. @cabeca
  2. @cabeca

    Refactored encoding of build output.

    cabeca authored
    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!
This page is out of date. Refresh to see the latest.
View
22 app/models/build.rb
@@ -73,8 +73,7 @@ def commit
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
@@ -86,22 +85,12 @@ def short_sha
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
@@ -109,8 +98,7 @@ def compose_output
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
View
1  config/initializers/encoding_detection.rb
@@ -1 +0,0 @@
-require 'charlock_holmes/string'
View
2  lib/gitlab_ci/encode.rb
@@ -1,3 +1,5 @@
+require 'charlock_holmes/string'
+
module GitlabCi
module Encode
extend self
View
6 lib/runner.rb
@@ -75,7 +75,7 @@ def command(cmd, path)
@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
@@ -98,7 +98,9 @@ def command(cmd, path)
@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)
Something went wrong with that request. Please try again.