65 lines
2.4 KiB
Diff
65 lines
2.4 KiB
Diff
From 3bcccf678040e827f706b8305456424aa83f6471 Mon Sep 17 00:00:00 2001
|
|
From: Loren Segal <lsegal@soen.ca>
|
|
Date: Thu, 23 Nov 2017 13:47:35 -0800
|
|
Subject: [PATCH] Fix broken tests
|
|
|
|
---
|
|
lib/yard/cli/yardoc.rb | 2 +-
|
|
lib/yard/core_ext/file.rb | 5 +++--
|
|
spec/core_ext/file_spec.rb | 4 ++++
|
|
3 files changed, 8 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/lib/yard/cli/yardoc.rb b/lib/yard/cli/yardoc.rb
|
|
index a2918a36..f40e4dd1 100644
|
|
--- a/lib/yard/cli/yardoc.rb
|
|
+++ b/lib/yard/cli/yardoc.rb
|
|
@@ -649,7 +649,7 @@ module YARD
|
|
opts.on('--asset FROM[:TO]', 'A file or directory to copy over to output ',
|
|
' directory after generating') do |asset|
|
|
re = %r{^(?:\.\./|/)}
|
|
- from, to = *asset.split(':').map {|f| File.cleanpath(f) }
|
|
+ from, to = *asset.split(':').map {|f| File.cleanpath(f, true) }
|
|
to ||= from
|
|
if from =~ re || to =~ re
|
|
log.warn "Invalid file '#{asset}'"
|
|
diff --git a/lib/yard/core_ext/file.rb b/lib/yard/core_ext/file.rb
|
|
index a0b983e9..c918b5af 100644
|
|
--- a/lib/yard/core_ext/file.rb
|
|
+++ b/lib/yard/core_ext/file.rb
|
|
@@ -32,15 +32,16 @@ class File
|
|
# @example Clean a path
|
|
# File.cleanpath('a/b//./c/../e') # => "a/b/e"
|
|
# @param [String] path the path to clean
|
|
+ # @param [Boolean] rel_root allows relative path above root value
|
|
# @return [String] the sanitized path
|
|
- def self.cleanpath(path)
|
|
+ def self.cleanpath(path, rel_root = false)
|
|
path = path.split(SEPARATOR)
|
|
path = path.inject([]) do |acc, comp|
|
|
next acc if comp == RELATIVE_SAMEDIR
|
|
if comp == RELATIVE_PARENTDIR && !acc.empty? && acc.last != RELATIVE_PARENTDIR
|
|
acc.pop
|
|
next acc
|
|
- elsif comp == RELATIVE_PARENTDIR && acc.empty?
|
|
+ elsif !rel_root && comp == RELATIVE_PARENTDIR && acc.empty?
|
|
next acc
|
|
end
|
|
acc << comp
|
|
diff --git a/spec/core_ext/file_spec.rb b/spec/core_ext/file_spec.rb
|
|
index 15806360..e3d3930c 100644
|
|
--- a/spec/core_ext/file_spec.rb
|
|
+++ b/spec/core_ext/file_spec.rb
|
|
@@ -41,6 +41,10 @@ RSpec.describe File do
|
|
expect(File.cleanpath('A/B/C/D/..')).to eq "A/B/C"
|
|
end
|
|
|
|
+ it "allows '../' at the beginning if rel_root=true" do
|
|
+ expect(File.cleanpath('A/../../B', true)).to eq '../B'
|
|
+ end
|
|
+
|
|
it "does not allow relative path above root" do
|
|
expect(File.cleanpath('A/../../../../../D')).to eq "D"
|
|
end
|
|
--
|
|
2.15.1
|
|
|