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 +.

Parameters:

  • (String)

Returns:

  • (String)


14
15
16
17
18
# File 'lib/vault/encode.rb', line 14

def encode_path(path)
  path.b.gsub(%r!([^a-zA-Z0-9_.-/]+)!) { |m|
    '%' + m.unpack('H2' * m.bytesize).join('%').upcase
  }
end