Sha256: ffc7d51a4435bd8349d1fc7096b4ff989a4f604f4c3ddce4eeddb0d425a14d1c

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module DeviseJwtAuth::Url

  def self.generate(url, params = {})
    uri = URI(url)

    res = "#{uri.scheme}://#{uri.host}"
    res += ":#{uri.port}" if (uri.port && uri.port != 80 && uri.port != 443)
    res += uri.path.to_s if uri.path
    query = [uri.query, params.to_query].reject(&:blank?).join('&')
    res += "?#{query}"
    res += "##{uri.fragment}" if uri.fragment
    # repeat any query params after the fragment to deal with Angular eating any pre fragment query params, used
    # in the reset password redirect url
    res += "?#{query}" if uri.fragment

    res
  end

  def self.whitelisted?(url)
    url.nil? || \
      !!DeviseJwtAuth.redirect_whitelist.find do |pattern|
        !!Wildcat.new(pattern).match(url)
      end
  end

  # wildcard convenience class
  class Wildcat
    def self.parse_to_regex(str)
      escaped = Regexp.escape(str).gsub('\*','.*?')
      Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
    end

    def initialize(str)
      @regex = self.class.parse_to_regex(str)
    end

    def match(str)
      !!@regex.match(str)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
devise_jwt_auth-0.1.5 lib/devise_jwt_auth/url.rb
devise_jwt_auth-0.1.4 lib/devise_jwt_auth/url.rb
devise_jwt_auth-0.1.3 lib/devise_jwt_auth/url.rb
devise_jwt_auth-0.1.2 lib/devise_jwt_auth/url.rb
devise_jwt_auth-0.1.1 lib/devise_jwt_auth/url.rb
devise_jwt_auth-0.1.0 lib/devise_jwt_auth/url.rb