Module: Vault::EncodePath

Included in:
Request
Defined in:
lib/vault/encode.rb

Class Method Summary collapse

Class Method Details

.encode_path(path) ⇒ String

Encodes a string according to the rules for URL paths. This is used as opposed to CGI.escape because in a URL path, space needs to be escaped as %20 and CGI.escapes a space as +.

take the implementation of ERB::Util.url_encode and modified it to exclude slash. source: apidock.com/ruby/v2_6_3/ERB/Util/url_encode

Parameters:

  • (String)

Returns:

  • (String)


17
18
19
20
21
# File 'lib/vault/encode.rb', line 17

def encode_path(path)
  path.to_s.b.gsub(/[^a-zA-Z0-9_\-.~\/]/) do |m|
    sprintf("%%%02X", m.unpack1("C"))
  end
end