Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix Rack::Utils.set_cookie_header! and delete_cookie_header! escaping
class << Rack::Utils
alias_method :escape_with_plus, :escape
def escape_without_plus(s)
URI.encode_www_form_component(s).gsub('+', '%20')
end
def mock_escape_for_cookies
singleton_class.send :alias_method, :escape, :escape_without_plus
yield
ensure
singleton_class.send :alias_method, :escape, :escape_with_plus
end
[:set_cookie_header!, :delete_cookie_header!].each do |name|
new_name = "#{name}_with_plus".to_sym
alias_method new_name, name
define_method name do |*args|
mock_escape_for_cookies do
send new_name, *args
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment