Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Escape filenames when using the shell.

  • Loading branch information...
commit e84130bf15dde42a0fa4647215b8916aa2c488eb 1 parent 9b0547a
@janfri authored
View
6 Changelog
@@ -1,6 +1,10 @@
+Version 1.1.0
+- Escaping filenames in shell commands
+ Thanks to Michael Hoy for the hint and implementing a patch which was
+ the base for this fix.
Version 1.0.2
- Fixing warings
- thanks to Peter-Hinrich Krogmann for the hint.
+ Thanks to Peter-Hinrich Krogmann for the hint.
Version 1.0.1
- Fixing bug [#22726]
Making MiniExiftool::Error public.
View
7 lib/mini_exiftool.rb
@@ -16,6 +16,7 @@
require 'tempfile'
require 'pstore'
require 'set'
+require 'shellwords'
# Simple OO access to the Exiftool command-line application.
class MiniExiftool
@@ -29,7 +30,7 @@ class MiniExiftool
attr_reader :filename
attr_accessor :numerical, :composite, :convert_encoding, :errors, :timestamps
- VERSION = '1.0.2'
+ VERSION = '1.1.0'
# +opts+ support at the moment
# * <code>:numerical</code> for numerical values, default is +false+
@@ -80,7 +81,7 @@ def load filename
opt_params << (@numerical ? '-n ' : '')
opt_params << (@composite ? '' : '-e ')
opt_params << (@convert_encoding ? '-L ' : '')
- cmd = %Q(#@@cmd -q -q -s -t #{opt_params} #{@@sep_op} "#{filename}")
+ cmd = %Q(#@@cmd -q -q -s -t #{opt_params} #{@@sep_op} #{Shellwords.escape(filename)})
if run(cmd)
parse_output
else
@@ -156,7 +157,7 @@ def save
opt_params = ''
opt_params << (arr_val.detect {|x| x.kind_of?(Numeric)} ? '-n ' : '')
opt_params << (@convert_encoding ? '-L ' : '')
- cmd = %Q(#@@cmd -q -P -overwrite_original #{opt_params} #{tag_params} "#{temp_filename}")
+ cmd = %Q(#@@cmd -q -P -overwrite_original #{opt_params} #{tag_params} #{temp_filename})
result = run(cmd)
unless result
all_ok = false
View
BIN  test/data/test 36"Bench.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
25 test/test_escape_filename.rb
@@ -0,0 +1,25 @@
+require 'helpers_for_test'
+
+class TestEscapeFilename < TestCase
+
+ def setup
+ @temp_file = Tempfile.new('test')
+ @temp_file.close
+ @temp_filename = @temp_file.path
+ @org_filename = File.dirname(__FILE__) + '/data/test 36"Bench.jpg'
+ FileUtils.cp(@org_filename, @temp_filename)
+ @mini_exiftool = MiniExiftool.new @temp_filename
+ end
+
+ def test_access
+ assert_equal '36" Bench', @mini_exiftool['description']
+ end
+
+ def test_save
+ desc = 'another bench'
+ @mini_exiftool.description = desc
+ assert @mini_exiftool.save
+ assert_equal desc, @mini_exiftool.description
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.