Skip to content

Commit

Permalink
Fix handling of relative paths that go outside the "initial" directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Mar 21, 2010
1 parent b41b46c commit d94bd3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/yard/core_ext/file.rb
Expand Up @@ -34,7 +34,7 @@ def self.cleanpath(path)
path = path.split(SEPARATOR)
path = path.inject([]) do |acc, comp|
next acc if comp == RELATIVE_SAMEDIR
if comp == RELATIVE_PARENTDIR && acc.size > 0
if comp == RELATIVE_PARENTDIR && acc.size > 0 && acc.last != RELATIVE_PARENTDIR
acc.pop
next acc
end
Expand Down
6 changes: 5 additions & 1 deletion spec/core_ext/file_spec.rb
Expand Up @@ -41,9 +41,13 @@
File.cleanpath('A/B/C/D/..').should == "A/B/C"
end

it "should not pass the initial directory" do
it "should pass the initial directory" do
File.cleanpath('C/../../D').should == "../D"
end

it "should not remove multiple '../' at the beginning" do
File.cleanpath('../../A/B').should == '../../A/B'
end
end

describe '.open!' do
Expand Down

0 comments on commit d94bd3d

Please sign in to comment.