Skip to content
This repository
Browse code

Switching from shellwords to manual escaping (Win support).

  • Loading branch information...
commit 9c219396ea43dd65ac0fe86be4029fafd3681b82 1 parent 6da0938
janfri authored May 07, 2013

Showing 1 changed file with 5 additions and 3 deletions. Show diff stats Hide diff stats

  1. 8  lib/mini_exiftool.rb
8  lib/mini_exiftool.rb
@@ -18,7 +18,6 @@
18 18
 require 'pstore'
19 19
 require 'rational'
20 20
 require 'set'
21  
-require 'shellwords'
22 21
 require 'time'
23 22
 
24 23
 # Simple OO access to the Exiftool command-line application.
@@ -90,7 +89,7 @@ def load filename
90 89
     opt_params << (@composite ? '' : '-e ')
91 90
     opt_params << (@convert_encoding ? '-L ' : '')
92 91
     opt_params << (@coord_format ? "-c \"#{@coord_format}\"" : '')
93  
-    cmd = %Q(#@@cmd -q -q -s -t #{opt_params} #{@@sep_op} #{Shellwords.escape(filename)})
  92
+    cmd = %Q(#@@cmd -q -q -s -t #{opt_params} #{@@sep_op} #{MiniExiftool.escape(filename)})
94 93
     if run(cmd)
95 94
       parse_output
96 95
     else
@@ -162,7 +161,7 @@ def save
162 161
       arr_val.map! {|e| convert e}
163 162
       tag_params = ''
164 163
       arr_val.each do |v|
165  
-        tag_params << %Q(-#{original_tag}=#{Shellwords.escape(v.to_s)} )
  164
+        tag_params << %Q(-#{original_tag}=#{MiniExiftool.escape(v)} )
166 165
       end
167 166
       opt_params = ''
168 167
       opt_params << (arr_val.detect {|x| x.kind_of?(Numeric)} ? '-n ' : '')
@@ -442,6 +441,9 @@ def self.determine_tags arg
442 441
     tags
443 442
   end
444 443
 
  444
+  def self.escape(val)
  445
+    '"' << val.to_s.gsub(/\\/, '\\'*4).gsub(/"/, '\"') << '"'
  446
+  end
445 447
 
446 448
   # Hash with indifferent access:
447 449
   # DateTimeOriginal == datetimeoriginal == date_time_original

0 notes on commit 9c21939

Please sign in to comment.
Something went wrong with that request. Please try again.