collectiveidea/graticule — pull request #24 by urbanautomaton (2012-04-02 16:19:11+00:00)
Title: Escape XML entities in GeoCoder::MapQuest queries

Hi,

I recently ran into a problem with the MapQuest geocoder whereby requests containing one of the basic XML entities (e.g. an ampersand) would receive a 400 Bad Request response from MapQuest, triggering a parsing error in happymapper when it tried to read the non-XML response body.

> geocoder = Graticule.service(:mapquest).new(blah, blah)
> geocoder.locate("Edwardsville City Park & Library, Edwardsville, United States")
Fatal error: Start tag expected, '<' not found at :1.
LibXML::XML::Error: Fatal error: Start tag expected, '<' not found at //gems/happymapper-0.4.0/lib/happymapper.rb:91.

Attached is a quick patch that uses the HTMLEntities to escape any basic entities found in the query string. I've updated the gemspec to reflect this new dependency, but I haven't checked in the updated Gemfile.lock, per Yehuda Katz's advice [here](http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/). If you'd like me to add it, though, I'm happy to.

Cheers,
Simon