Skip to content
This repository
Browse code

escape commas in paths before globbing to avoid infinite hang in Dir[]

  • Loading branch information...
commit 4073505065a0937d67c45860988fbe634a700c37 1 parent fbc9d0f
Jon Rowe authored March 15, 2012
6  activesupport/lib/active_support/file_update_checker.rb
@@ -106,11 +106,15 @@ def compile_glob(hash) #:nodoc:
106 106
 
107 107
       globs = []
108 108
       hash.each do |key, value|
109  
-        globs << "#{key}/**/*#{compile_ext(value)}"
  109
+        globs << "#{escape(key)}/**/*#{compile_ext(value)}"
110 110
       end
111 111
       "{#{globs.join(",")}}"
112 112
     end
113 113
 
  114
+    def escape(key)
  115
+      key.gsub(',','\,')
  116
+    end
  117
+
114 118
     def compile_ext(array) #:nodoc:
115 119
       array = Array(array)
116 120
       return if array.empty?
15  activesupport/test/file_update_checker_test.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'abstract_unit'
2 2
 require 'fileutils'
  3
+require 'thread'
3 4
 
4 5
 MTIME_FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
5 6
 
@@ -79,4 +80,18 @@ def test_should_not_invoke_the_block_if_a_watched_dir_changed_its_glob
79 80
     assert !checker.execute_if_updated
80 81
     assert_equal 0, i
81 82
   end
  83
+
  84
+  def test_should_not_block_if_a_strange_filename_used
  85
+    FileUtils.mkdir_p("tmp_watcher/valid,yetstrange,path,")
  86
+    FileUtils.touch(FILES.map { |file_name| "tmp_watcher/valid,yetstrange,path,/#{file_name}" } )
  87
+
  88
+    test = Thread.new do
  89
+      checker = ActiveSupport::FileUpdateChecker.new([],"tmp_watcher/valid,yetstrange,path," => :txt){ i += 1 }
  90
+      Thread.exit
  91
+    end
  92
+    test.priority = -1
  93
+    test.join(5)
  94
+
  95
+    assert !test.alive?
  96
+  end
82 97
 end

0 notes on commit 4073505

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