Skip to content

Commit 4073505

Browse files
committed
escape commas in paths before globbing to avoid infinite hang in Dir[]
1 parent fbc9d0f commit 4073505

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

activesupport/lib/active_support/file_update_checker.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ def compile_glob(hash) #:nodoc:
106106

107107
globs = []
108108
hash.each do |key, value|
109-
globs << "#{key}/**/*#{compile_ext(value)}"
109+
globs << "#{escape(key)}/**/*#{compile_ext(value)}"
110110
end
111111
"{#{globs.join(",")}}"
112112
end
113113

114+
def escape(key)
115+
key.gsub(',','\,')
116+
end
117+
114118
def compile_ext(array) #:nodoc:
115119
array = Array(array)
116120
return if array.empty?

activesupport/test/file_update_checker_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'abstract_unit'
22
require 'fileutils'
3+
require 'thread'
34

45
MTIME_FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
56

@@ -79,4 +80,18 @@ def test_should_not_invoke_the_block_if_a_watched_dir_changed_its_glob
7980
assert !checker.execute_if_updated
8081
assert_equal 0, i
8182
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
8297
end

0 commit comments

Comments
 (0)