From f38a658df614bf31bc68dbb5f2898557ea38913f Mon Sep 17 00:00:00 2001 From: Matthew Hutchinson Date: Sun, 19 Apr 2015 11:58:44 +0100 Subject: [PATCH] fixing windows mini_magick escape issues --- .rubocop_todo.yml | 5 ----- .travis.yml | 2 +- lib/core_ext/mini_magick/utilities.rb | 20 ++++++++++++++++++++ lib/lolcommits.rb | 1 + lib/lolcommits/plugins/tranzlate.rb | 2 +- lolcommits.gemspec | 2 +- 6 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 lib/core_ext/mini_magick/utilities.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e8ba448e..4ab81431 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -32,11 +32,6 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 11 -# Offense count: 1 -# Cop supports --auto-correct. -Performance/Sample: - Enabled: false - # Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/.travis.yml b/.travis.yml index a490e243..f0efeae0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ rvm: - 1.9.3 - 2.0.0 - 2.1.5 - - 2.2.1 + - 2.2.2 - ruby-head before_install: diff --git a/lib/core_ext/mini_magick/utilities.rb b/lib/core_ext/mini_magick/utilities.rb new file mode 100644 index 00000000..dfc0f6e5 --- /dev/null +++ b/lib/core_ext/mini_magick/utilities.rb @@ -0,0 +1,20 @@ +# -*- encoding : utf-8 -*- +module CoreExt + module MiniMagick + module Utilities + class << self + # fixes issue introduced in this commit + # https://github.com/minimagick/minimagick/commit/65b6427395cbfe6 + def windows_escape(cmdline) + '"' + cmdline.gsub(/\\(?=\\*\")/, '\\\\\\').gsub(/\"/, '\\"').gsub(/\\$/, '\\\\\\').gsub('%', '%%') + '"' + end + end + end + end +end + +# To maintain MiniMagick compatibility on Windows for v3.8.1 we need this patch +# If/when we upgrade MiniMagick to 4.2+ this patch can be removed +# We are locked at v3.8.1 since MiniMagick 4+ dropped support for Ruby 1.8.7 + +MiniMagick.send(:include, CoreExt::MiniMagick::Utilities) diff --git a/lib/lolcommits.rb b/lib/lolcommits.rb index dac91e7c..3830ea59 100644 --- a/lib/lolcommits.rb +++ b/lib/lolcommits.rb @@ -3,6 +3,7 @@ require 'core_ext/class' require 'mini_magick' +require 'core_ext/mini_magick/utilities' require 'fileutils' require 'git' require 'open3' diff --git a/lib/lolcommits/plugins/tranzlate.rb b/lib/lolcommits/plugins/tranzlate.rb index 9b4fd67e..a0add85b 100644 --- a/lib/lolcommits/plugins/tranzlate.rb +++ b/lib/lolcommits/plugins/tranzlate.rb @@ -85,7 +85,7 @@ def tranzlate(str) lolstr = str.dup LOL_DICTIONARY.each do |english, lolspeak| # ghetto ruby1.8/1.9 agnostic version of choice vs sample - lolstr.gsub!(english, lolspeak.shuffle.first) + lolstr.gsub!(english, lolspeak.sample) end lolstr << '! kthxbye!' if rand(10) == 2 diff --git a/lolcommits.gemspec b/lolcommits.gemspec index 87b55775..968efd6f 100644 --- a/lolcommits.gemspec +++ b/lolcommits.gemspec @@ -59,6 +59,6 @@ Gem::Specification.new do |s| if RUBY_VERSION >= '1.9.3' s.add_development_dependency('travis', '~> 1.7.4') - s.add_development_dependency('rubocop', '~> 0.28') + s.add_development_dependency('rubocop', '~> 0.30') end end