Merge pull request #2109 from jekyll/proper-path-cleaning
This commit is contained in:
commit
215e91cade
|
@ -106,19 +106,16 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the root of the filesystem as a Pathname
|
# Returns the root of the filesystem as a Pathname
|
||||||
def self.fs_root
|
def self.fs_root
|
||||||
@fs_root ||= traverse_up(Pathname.new(Dir.pwd))
|
@fs_root ||= "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sanitized_path(base_directory, questionable_path)
|
def self.sanitized_path(base_directory, questionable_path)
|
||||||
clean_path = File.expand_path(questionable_path, fs_root)
|
clean_path = File.expand_path(questionable_path, fs_root)
|
||||||
clean_path.sub(/\A[\w]:\\\\/, '')
|
clean_path.gsub!(/\w\:\//, '/')
|
||||||
File.join(base_directory, clean_path)
|
unless clean_path.start_with?(base_directory)
|
||||||
end
|
File.join(base_directory, clean_path)
|
||||||
|
else
|
||||||
private
|
clean_path
|
||||||
|
end
|
||||||
def self.traverse_up(pathname)
|
|
||||||
return pathname if pathname.parent.eql?(pathname)
|
|
||||||
traverse_up(pathname.parent)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
class TestPathSanitization < Test::Unit::TestCase
|
||||||
|
context "on Windows with absolute source" do
|
||||||
|
setup do
|
||||||
|
@source = "C:/Users/xmr/Desktop/mpc-hc.org"
|
||||||
|
@dest = "./_site/"
|
||||||
|
stub(Dir).pwd { "C:/Users/xmr/Desktop/mpc-hc.org" }
|
||||||
|
end
|
||||||
|
should "strip drive name from path" do
|
||||||
|
assert_equal "C:/Users/xmr/Desktop/mpc-hc.org/_site", Jekyll.sanitized_path(@source, @dest)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue