diff --git a/lib/yard/core_ext/file.rb b/lib/yard/core_ext/file.rb index 938652081..20e98538e 100644 --- a/lib/yard/core_ext/file.rb +++ b/lib/yard/core_ext/file.rb @@ -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 diff --git a/spec/core_ext/file_spec.rb b/spec/core_ext/file_spec.rb index 153e816c6..7bba3d2dd 100644 --- a/spec/core_ext/file_spec.rb +++ b/spec/core_ext/file_spec.rb @@ -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