diff --git a/lib/sass_spec/directory.rb b/lib/sass_spec/directory.rb index 878f7a5387..9cfdc307fe 100644 --- a/lib/sass_spec/directory.rb +++ b/lib/sass_spec/directory.rb @@ -164,9 +164,14 @@ def delete_dir! def with_real_files return yield unless @archive + files = @archive.entries.select {|entry| entry.is_a?(HRX::File)}.to_a + if parent.hrx? && files.any? {|file| _reaches_out?(file)} + return parent.with_real_files {yield} + end + outermost_new_dir = SassSpec::Util.each_directory(@path).find {|dir| !Dir.exist?(dir)} - @archive.entries.select {|entry| entry.is_a?(HRX::File)}.each do |file| + files.each do |file| path = File.join(@path, file.path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, file.content) @@ -195,6 +200,13 @@ def to_s private + # Returns whether `file` contains enough `../` references to reach outside + # this directory. + def _reaches_out?(file) + depth = file.path.count("/") + file.content.scan(%r{(?:\.\./)+}).any? {|match| match.count("/") > depth} + end + # Writes `@parent_archive` to disk. def _write! @parent_archive.write!(@parent_archive_path)