From 5856b704007db12fb64f204ec42491992934f2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Seux?= Date: Wed, 7 Dec 2016 17:19:00 +0100 Subject: [PATCH 1/2] Assume strings are utf8 by default and fallback on encoding if necessary Before this patch, we always assumed the string was ascii-8bit which does not work correctly with real utf8 strings (french accented chars or chineese chars). This patch tries to use the string as utf8 and fallback if necessary to the the ascii-8bit assumption if necessary. This should help with #295 and might replace the need for #301. Change-Id: Idac63fa10e5aefafa1eb99a6be4138cac5f90ea0 --- lib/git/lib.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 777e42ea..f95452a4 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -859,13 +859,28 @@ def meets_required_version? def command_lines(cmd, opts = [], chdir = true, redirect = '') cmd_op = command(cmd, opts, chdir) - op = cmd_op.encode("UTF-8", "binary", { - :invalid => :replace, - :undef => :replace - }) - op.split("\n") + split_utf8(cmd_op) end + def split_utf8(s) + # ruby can think the string is utf8 but any action on the strings chars + # will trigger errors. Here we try to split utf8 strings. + # It it isn't utf8 or if it fails, we fallback to assume the input is + # "binary" encoding + result = begin + s.encoding == Encoding::UTF_8 && s.split("\n") + rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError + nil + end + + result ||= s.encode("UTF-8", "binary", { + :invalid => :replace, + :undef => :replace, + }).split("\n") + result + end + + # Takes the current git's system ENV variables and store them. def store_git_system_env_variables @git_system_env_variables = {} From 8908c3d310239e767db558887470a862211c5ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Seux?= Date: Wed, 7 Dec 2016 17:34:31 +0100 Subject: [PATCH 2/2] Drop support for ruby 1.9.2 ruby 1.9.2 has been out of support for 2,5 years (https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/) The motivation behind this removal is the fact that all dependencies of this gem (at least rake and rdoc) do not support ruby 1.9.2 in their latest versions. Keeping support would require to constraint their version to very old version (on ruby 1.9.2 only). Actually even 1.9.3 has been out of support for 1,5 years but it does not cause test problem yet. Change-Id: Iad7c3da74a19ebc37c3df4203f7e55a0b5aa70dc --- .travis.yml | 1 - git.gemspec | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2ea18fc..57d5041a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: ruby rvm: - - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.1 diff --git a/git.gemspec b/git.gemspec index 5e90626e..be398103 100644 --- a/git.gemspec +++ b/git.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.version = '1.3.0' s.require_paths = ['lib'] - s.required_ruby_version = '>= 1.9' + s.required_ruby_version = '>= 1.9.3' s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.requirements = ['git 1.6.0.0, or greater']