module Conjur::Escape::ClassMethods

Public Instance Methods

fully_escape(str) click to toggle source

URL escape the entire string. This is essentially the same as calling ‘CGI.escape str`, and then substituting `%20` for `+`.

@example

fully_escape 'foo/bar@baz'
# => "foo%2Fbar%40baz"

@example

fully_escape 'test/Domain Controllers'
# => "test%2FDomain%20Controllers"

@param [String] str the string to escape @return [String] the escaped string

# File lib/conjur/escape.rb, line 41
def fully_escape(str)
  # CGI escape uses + for spaces, which our services don't support :-(
  # We just gsub it.
  CGI.escape(str.to_s).gsub('+', '%20')
end
path_escape(str) click to toggle source

Escape a URI path component.

This method simply calls {Conjur::Escape::ClassMethods#path_or_query_escape}.

@param [String] str the string to escape @return [String] the escaped string @see Conjur::Escape::ClassMethods#path_or_query_escape

# File lib/conjur/escape.rb, line 55
def path_escape(str)
  path_or_query_escape str
end
path_or_query_escape(str) click to toggle source

Escape a path or query value.

This method is similar to ‘URI.escape`, but it has several important differences:

* If a falsey value is given, the string `"false"` is returned.
* If the value given responds to `#id`, the value returned by `str.id` is escaped instead.
* The value is escaped without modifying `':'` or `'/'`.

@param [String, FalseClass, NilClass, id] str the value to escape @return [String] the value escaped as described

# File lib/conjur/escape.rb, line 79
def path_or_query_escape(str)
  return "false" unless str
  str = str.id if str.respond_to?(:id)
  # Leave colons and forward slashes alone
  require 'addressable/uri'
  Addressable::URI.encode(str.to_s)
end
query_escape(str) click to toggle source

Escape a URI query value.

This method simply calls {Conjur::Escape::ClassMethods#path_or_query_escape}.

@param [String] str the string to escape @return [String] the escaped string @see Conjur::Escape::ClassMethods#path_or_query_escape

# File lib/conjur/escape.rb, line 66
def query_escape(str)
  path_or_query_escape str
end