lib/rb-fsevent/fsevent.rb in rb-fsevent-0.3.4 vs lib/rb-fsevent/fsevent.rb in rb-fsevent-0.3.5
- old
+ new
@@ -23,11 +23,11 @@
def bin_path
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin'))
end
def launch_bin
- @pipe = IO.popen("#{bin_path}/fsevent_watch #{path.shellescape}")
+ @pipe = IO.popen("#{bin_path}/fsevent_watch #{shellescape(path)}")
end
def listen
while !pipe.eof?
if line = pipe.readline
@@ -35,8 +35,26 @@
callback.call(modified_dir_paths)
end
end
rescue Interrupt
stop
+ end
+
+ # for Ruby 1.8.6 support
+ def shellescape(str)
+ # An empty argument will be skipped, so return empty quotes.
+ return "''" if str.empty?
+
+ str = str.dup
+
+ # Process as a single byte sequence because not all shell
+ # implementations are multibyte aware.
+ str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
+
+ # A LF cannot be escaped with a backslash because a backslash + LF
+ # combo is regarded as line continuation and simply ignored.
+ str.gsub!(/\n/, "'\n'")
+
+ return str
end
end
\ No newline at end of file