Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Prevent calling CGI.escape on a SafeBuffer #399

wants to merge 1 commit into from

2 participants


I don't know if this is the right place for this but similar to this issue: rails/rails#1555 when the CGI.escape i.to_s call is made and i is an ActiveSupport::SafeBuffer, then it blows up with a NoMethodError: undefined methodbytesize' for nil:NilClass` error.

This may be overly defensive coding, but using to_s.to_str ensures that whatever CGI.escape sees is surely a string.


Was this inspired by an actual error? I'm having a hard time imagining a situation in which a query option is a SafeBuffer.


Yes it was. But now that you mention it, it does seem like an unlikely situation. Pretty much just a defensive hack. Just something to consider. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/geocoder/lookups/base.rb
2  lib/geocoder/lookups/base.rb
@@ -242,7 +242,7 @@ def cache
def hash_to_query(hash)
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
hash.collect{ |p|
- p[1].nil? ? nil :{ |i| CGI.escape i.to_s } * '='
+ p[1].nil? ? nil :{ |i| CGI.escape i.to_s.to_str } * '='
}.compact.sort * '&'
Something went wrong with that request. Please try again.