File: utils.rb

package info (click to toggle)
ruby-roadie 5.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 512 kB
  • sloc: ruby: 3,418; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (2)
1
2
3
4
5
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
# frozen_string_literal: true

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

      begin
        !URI.parse(path).relative?
      rescue URI::InvalidURIError => error
        raise InvalidUrlPath.new(path, error)
      end
    end
    # @api private
    module_function :path_is_absolute?

    # @api private
    def warn(message)
      Kernel.warn("Roadie: #{message}")
    end
    # @api private
    module_function :warn
  end
end