Skip to content

Commit fd86ddd

Browse files
author
David Vartanian
committed
Fix the encoding issue - 'split': invalid byte sequence in UTF-8 (Argument Error) ruby-git#190 - from up-to-date master
1 parent 14738bb commit fd86ddd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/git/diff.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def process_full_diff
124124
}
125125
final = {}
126126
current_file = nil
127-
@full_diff.split("\n").each do |line|
127+
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", :invalid => "replace", :undef => "replace")
128+
full_diff_utf8_encoded.split("\n").each do |line|
128129
if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
129130
current_file = m[1]
130131
final[current_file] = defaults.merge({:patch => line, :path => current_file})

lib/git/lib.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,9 @@ def meets_required_version?
843843
ENV_VARIABLE_NAMES = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_SSH']
844844

845845
def command_lines(cmd, opts = [], chdir = true, redirect = '')
846-
command(cmd, opts, chdir).split("\n")
846+
cmd_op = command(cmd, opts, chdir)
847+
op = cmd_op.encode("UTF-8", "binary", :invalid => "replace", :undef => "replace")
848+
op.split("\n")
847849
end
848850

849851
# Takes the current git's system ENV variables and store them.

0 commit comments

Comments
 (0)