diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-09 06:25:10 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-09 06:25:10 +0100 |
commit | 2995134cba898c95d62bb9756742959a0839cbf0 (patch) | |
tree | a2253280318ce1cb086dd91359e5d8715b6fcc43 /actionpack | |
parent | 1d9de9d7585f2c753b629080b1239969aaf8499a (diff) | |
download | rails-2995134cba898c95d62bb9756742959a0839cbf0.tar.gz rails-2995134cba898c95d62bb9756742959a0839cbf0.tar.bz2 rails-2995134cba898c95d62bb9756742959a0839cbf0.zip |
Simplify path traversal logic
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/renderer/partial_renderer.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index f7af7a8a0a..d052c26381 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -375,23 +375,23 @@ module ActionView end end - @partial_names[path] ||= path.dup.tap do |object_path| - merge_prefix_into_object_path(@context_prefix, object_path) - end + @partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup) end def merge_prefix_into_object_path(prefix, object_path) if prefix.include?(?/) && object_path.include?(?/) - overlap = [] + prefixes = [] prefix_array = File.dirname(prefix).split('/') object_path_array = object_path.split('/')[0..-3] # skip model dir & partial prefix_array.each_with_index do |dir, index| - overlap << dir if dir == object_path_array[index] + break if dir == object_path_array[index] + prefixes << dir end - object_path.gsub!(/^#{overlap.join('/')}\//,'') - object_path.insert(0, "#{File.dirname(prefix)}/") + (prefixes << object_path).join("/") + else + object_path end end |