Module: Conjur::Escape::ClassMethods
- Defined in:
- lib/conjur/escape.rb
Instance Method Summary collapse
-
#fully_escape(str) ⇒ String
URL escape the entire string.
-
#path_escape(str) ⇒ String
Escape a URI path component.
-
#path_or_query_escape(str) ⇒ String
Escape a path or query value.
-
#query_escape(str) ⇒ String
Escape a URI query value.
Instance Method Details
#fully_escape(str) ⇒ String
URL escape the entire string. This is essentially the same as calling CGI.escape str.
40 41 42 43 44 |
# File 'lib/conjur/escape.rb', line 40 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) ⇒ String
Escape a URI path component.
This method simply calls #path_or_query_escape.
54 55 56 |
# File 'lib/conjur/escape.rb', line 54 def path_escape(str) path_or_query_escape str end |
#path_or_query_escape(str) ⇒ String
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 bystr.idis escaped instead. - The value is escaped without modifying
':'or'/'.
78 79 80 81 82 83 84 85 |
# File 'lib/conjur/escape.rb', line 78 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 'uri' pattern = URI::PATTERN::UNRESERVED + ":\\/@" URI.escape(str.to_s, Regexp.new("[^#{pattern}]")) end |
#query_escape(str) ⇒ String
Escape a URI query value.
This method simply calls #path_or_query_escape.
65 66 67 |
# File 'lib/conjur/escape.rb', line 65 def query_escape(str) path_or_query_escape str end |