Mange / roadie
1
# frozen_string_literal: true
2

3 5
module Roadie
4 5
  module Utils
5
    # @api private
6 5
    def path_is_absolute?(path)
7
      # Ruby's URI is pretty unforgiving, but roadie aims to be. Don't involve
8
      # URI for URLs that's easy to determine to be absolute.
9
      # URLs starting with a scheme (http:, data:) are absolute.
10
      #
11
      # URLs that start with double slashes (//css/app.css) are also absolute
12
      # in modern browsers, but most email clients do not understand them.
13 5
      return true if path =~ %r{^(\w+:|//)}
14

15 3
      begin
16 5
        !URI.parse(path).relative?
17 4
      rescue URI::InvalidURIError => error
18 5
        raise InvalidUrlPath.new(path, error)
19
      end
20
    end
21
    # @api private
22 5
    module_function :path_is_absolute?
23

24
    # @api private
25 5
    def warn(message)
26 5
      Kernel.warn("Roadie: #{message}")
27
    end
28
    # @api private
29 5
    module_function :warn
30
  end
31
end

Read our documentation on viewing source code .

Loading