Skip to content

Instantly share code, notes, and snippets.

@johnthethird
Created March 10, 2010 16:44
Show Gist options
  • Save johnthethird/328053 to your computer and use it in GitHub Desktop.
Save johnthethird/328053 to your computer and use it in GitHub Desktop.
# This patch to the Ripple gem will properly escape key names with slashes and + signs
# in them. Nice for trying to store a file directory structure in Riak.
module Riak
class Client
class HTTPBackend
def path(*segments)
query = segments.extract_options!.to_param
uri = root_uri.merge(URI.escape(segments.join("/").gsub(/\/+/, "/").sub(/^\//, ''))).tap do |u|
u.query = query if query.present?
end
# This line is the patch...
uri.path = "#{$1}#{$2.gsub(%r{/},'%2F').gsub(%r{\+},'%2B')}" if uri.path =~ %r{(/[^/]+/[^/]+/)(.*)}
uri
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment