Module: Watobo::Utils::URL

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

Class Method Summary collapse

Class Method Details

.create_url(chat, path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/watobo/utils/url.rb', line 5

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