Sha256: 3db141e8103395596b0e8a49e875ca68b27aec32f84845f895edd59b4fa03ce4

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

module Hawkular
  module ClientUtils
    # Escapes the passed url part. This is necessary,
    # as many ids inside Hawkular can contain characters
    # that are invalid for an url/uri.
    # The passed value is duplicated
    # Does not escape the = character
    # @param [String] url_part Part of an url to be escaped
    # @return [String] escaped url_part as new string
    def hawk_escape(url_part)
      return url_part.to_s if url_part.is_a?(Numeric)

      url_part
        .to_s
        .dup
        .gsub('%', '%25')
        .gsub(' ', '%20')
        .gsub('[', '%5b')
        .gsub(']', '%5d')
        .gsub('|', '%7c')
        .gsub('(', '%28')
        .gsub(')', '%29')
        .gsub('/', '%2f')
    end

    # Escapes the passed url part. This is necessary,
    # as many ids inside Hawkular can contain characters
    # that are invalid for an url/uri.
    # The passed value is duplicated
    # Does escape the = character
    # @param [String] url_part Part of an url to be escaped
    # @return [String] escaped url_part as new string
    def hawk_escape_id(url_part)
      hawk_escape(url_part)
        .gsub('=', '%3d')
        .gsub(';', '%3b')
    end
  end
end

HawkularUtilsMixin = Hawkular::ClientUtils
deprecate_constant(:HawkularUtilsMixin) if self.respond_to?(:deprecate_constant)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hawkular-client-2.9.0 lib/hawkular/client_utils.rb