6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/blinkr/http_utils.rb', line 6
def sanitize(dest, src)
return nil if (dest.nil? || src.nil?)
src = src[0, src.rindex('#!')] unless src.rindex('#!').nil?
src_uri = URI(src)
src_uri.query = nil
src_uri.fragment = nil
base_uri = URI(@config.base_url)
begin
dest_uri = URI(dest)
dest_uri.fragment = nil if @config.ignore_fragments
dest_uri = URI.join(src_uri, dest) if (empty?(dest_uri.path) && !empty?(dest_uri.fragment)) || dest_uri.relative?
dest_uri = URI.join(base_uri.scheme, base_uri.hostname, base_uri.port, dest_uri) if empty?(dest_uri.scheme) && empty?(dest_uri.hostname)
dest_uri.path = dest_uri.path.gsub(/\/+/, '/') if dest_uri.path
dest_uri.query = dest_uri.query.gsub(/\/+/, '/') if dest_uri.query
dest_uri.fragment = dest_uri.query.gsub(/\/+/, '/') if dest_uri.fragment
dest = dest_uri.to_s
rescue URI::InvalidURIError, URI::InvalidComponentError, URI::BadURIError
rescue StandardError
return nil
end
dest.chomp('#').chomp('index.html')
end
|