Method: Rex::FileUtils.clean_path

Defined in:
lib/rex/file.rb

.clean_path(old) ⇒ Object

This method cleans the supplied path of directory traversal sequences It must accept path/with/..a/folder../starting/or/ending/in/two/dots but clean ../something as well as path/with/..traversal



68
69
70
71
72
73
74
75
76
# File 'lib/rex/file.rb', line 68

def self.clean_path(old)
  path = old
  while(path.index(/\/..\/|\/..\\|\\..\\|\\..\/|\A..\\|\A..\//) != nil)
    path.gsub!(/\A..\\|\A..\//,'') #eliminate starting ..\ or ../
    path.gsub!(/\/..\/|\/..\\/,'/') #clean linux style
    path.gsub!(/\\..\\|\\..\//,'\\') #clean windows style
  end
  path
end