forked from wconrad/ftpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced File.expand_path with custom expand_path that works also on …
…windows.
- Loading branch information
1 parent
fa41abf
commit dfb1c3b
Showing
4 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Ftpd | ||
module PathHelper | ||
def self.expand_path(file_name, dir_string) | ||
File.expand_path(file_name, dir_string) | ||
|
||
if file_name.start_with?("/") or file_name.start_with?("\\") then | ||
parts = file_name.split(/[\/\\]/) | ||
else | ||
parts = dir_string.split(/[\/\\]/) + file_name.split(/[\/\\]/) | ||
end | ||
|
||
new_parts = [] | ||
parts.each do |p| | ||
case p | ||
when "" | ||
when "." | ||
when ".." | ||
new_parts.pop | ||
else | ||
new_parts << p | ||
end | ||
end | ||
|
||
"/" + new_parts.join("/") | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require File.expand_path('spec_helper', File.dirname(__FILE__)) | ||
|
||
module Ftpd | ||
describe PathHelper do | ||
describe :expand_path do | ||
it "should return root path if given two empty paths" do | ||
PathHelper.expand_path("", "").should == "/" | ||
end | ||
|
||
it "should return parent if file_name is .." do | ||
PathHelper.expand_path("..", "/foo/bar").should == "/foo" | ||
end | ||
|
||
|
||
it "should return same if file_name is ." do | ||
PathHelper.expand_path(".", "/foo/bar").should == "/foo/bar" | ||
end | ||
|
||
it "should return subdir with single element file_name" do | ||
PathHelper.expand_path("baz", "/foo/bar").should == "/foo/bar/baz" | ||
end | ||
|
||
it "should return subdir with file_name starting with ./" do | ||
PathHelper.expand_path("./baz", "/foo/bar").should == "/foo/bar/baz" | ||
end | ||
|
||
it "should handle incorporated .. in file_name" do | ||
PathHelper.expand_path("../baz", "/foo/bar").should == "/foo/baz" | ||
end | ||
|
||
it "should handle extra .. in file_name" do | ||
PathHelper.expand_path("../../../../../baz", "/foo/bar").should == "/baz" | ||
end | ||
|
||
it "it should return file_name if it is absolute path" do | ||
PathHelper.expand_path("/foo/bar/baz", "/should/ignore/me").should == "/foo/bar/baz" | ||
end | ||
end | ||
end | ||
end | ||
|
dfb1c3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-s-anderson, @m0x is investigating multiple problems with FTPD under Windows, one of which is with the file system. I wonder if this patch fixes any of the issues that @m0x is seeing. We're discussing it over here.