Module: Watobo::Utils::URL

Defined in:
lib/watobo/utils/url.rb

Class Method Summary collapse

Class Method Details

.create_url(chat, path) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/watobo/utils/url.rb', line 26

def self.create_url(chat, path)
  url = path
  # only expand path if not url
  unless path =~ /^http/
    # check if path is absolute
    if path =~ /^\//
      url = File.join("#{chat.request.proto}://#{chat.request.host}", path)
    else
      # it's relative
      url = File.join(File.dirname(chat.request.url.to_s), path)
    end
  end
  # resolve path traversals
  while url =~ /(\/[^\.\/]*\/\.\.\/)/
    url.gsub!( $1,"/")
  end
  url
end