Module: Riak::Util::Escape

Included in:
Client, Client::Node, Client::ProtobuffsBackend, Link, MapReduce, RObject, RObject, WalkSpec
Defined in:
lib/riak/util/escape.rb

Overview

Methods for escaping URL segments.

Instance Method Summary collapse

Instance Method Details

#escape(bucket_or_key) ⇒ String

Escapes bucket or key names that may contain slashes for use in URLs.

Parameters:

  • bucket_or_key (String)

    the bucket or key name

Returns:

  • (String)

    the escaped path segment



67
68
69
70
71
72
73
# File 'lib/riak/util/escape.rb', line 67

def escape(bucket_or_key)
  if Riak.escaper == URI
    Riak.escaper.escape(bucket_or_key.to_s).gsub(/[ \+\/]/, { " " => "%20", "+" => "%2B", "/" => "%2F"})
  else #CGI
    Riak.escaper.escape(bucket_or_key.to_s).gsub(/[\+\/]/, { "+" => "%20", "/" => "%2F"})
  end
end

#maybe_escape(bucket_or_key) ⇒ String

Conditionally escapes buckets and keys depending on whether Riak is configured to decode them. This is used in situations where the bucket or key is not part of a URL, but would need to be escaped on Riak 0.14 and earlier so that the name matches.

Parameters:

  • bucket_or_key (String)

    the bucket or key name

Returns:

  • (String)

    the escaped path segment



60
61
62
# File 'lib/riak/util/escape.rb', line 60

def maybe_escape(bucket_or_key)
  Riak.url_decoding ? bucket_or_key : escape(bucket_or_key)
end

#maybe_unescape(bucket_or_key) ⇒ String

Conditionally unescapes buckets and keys depending on whether Riak is configured to decode them. This is used in situations where the bucket or key is not part of a URL, but would need to be escaped on Riak 0.14 and earlier so that the name matches.

Parameters:

  • bucket_or_key (String)

    the escaped bucket or key name

Returns:

  • (String)

    the unescaped path segment



82
83
84
# File 'lib/riak/util/escape.rb', line 82

def maybe_unescape(bucket_or_key)
  Riak.url_decoding ? bucket_or_key : unescape(bucket_or_key)
end

#unescape(bucket_or_key) ⇒ String

Unescapes bucket or key names in URLs.

Parameters:

  • bucket_or_key (String)

    the bucket or key name

Returns:

  • (String)

    the unescaped name



89
90
91
# File 'lib/riak/util/escape.rb', line 89

def unescape(bucket_or_key)
  Riak.escaper.unescape(bucket_or_key.to_s)
end