Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Materialize parent HRX directories if necessary #1408

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/sass_spec/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if file paths have trailing slashes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HRX spec guarantees that they won't; otherwise they'd be parsed as HRX::Directorys instead.

file.content.scan(%r{(?:\.\./)+}).any? {|match| match.count("/") > depth}
end

# Writes `@parent_archive` to disk.
def _write!
@parent_archive.write!(@parent_archive_path)
Expand Down