Code Monkey home page Code Monkey logo

Comments (6)

oschwald avatar oschwald commented on July 30, 2024

The encoding of the database file has not changed. The strings are stored internally as ISO-8859-1.

from geoip.

cjheath avatar cjheath commented on July 30, 2024

I think Gregory is right, which means I need to add conversions to all strings. That won't happen for a while, unless I get a solid PR from someone else.

from geoip.

riffraff avatar riffraff commented on July 30, 2024

Thanks for the replies and sorry for misinterpreting IRB's output.

If the db encoding is not changed than I think the problem is limited to changing https://github.com/cjheath/geoip/blob/master/lib/geoip.rb#L792, i.e. almost all fields are already in UTF-8 except for city_name (I believe that all other fields are in fact plain ASCII and city_name is the only one likely to yield characters outside of ASCII).

E.g. notice the difference between "Sao Paulo" as timezone, city_name and region_name.

geoip.city("200.220.180.2").each.map {|k| [k, k.encoding] if k.respond_to? :encoding }}
=> [["200.220.180.2", #<Encoding:UTF-8>],
 ["200.220.180.2", #<Encoding:UTF-8>],
 ["BR", #<Encoding:UTF-8>],
 ["BRA", #<Encoding:UTF-8>],
 ["Brazil", #<Encoding:UTF-8>],
 ["SA", #<Encoding:UTF-8>],
 ["27", #<Encoding:ASCII-8BIT>],
 ["S\xE3o Paulo", #<Encoding:ISO-8859-1>],
 ["", #<Encoding:ASCII-8BIT>],
 nil,
 nil,
 nil,
 nil,
 ["America/Sao_Paulo", #<Encoding:UTF-8>],
 ["Sao Paulo", #<Encoding:UTF-8>]]

(I am not sure why region_name and postal_code are ASCII-8BIT but since it's a subset of utf-8 anyway that doesn't cause issues)

So the only change would be

city.force_encoding('iso-8859-1') if city.respond_to?(:force_encoding)

to

if city.respond_to?(:force_encoding)
  city.force_encoding('iso-8859-1').encode('utf-8')
end

I can add a couple tests and make the change and send a pull request, but I couldn't find tests for the city database, are there any?

from geoip.

epitron avatar epitron commented on July 30, 2024

I just ran into this issue today as well.

The one-line fix that the previous poster suggested looks good to me:

city.force_encoding('iso-8859-1').encode('utf-8') if city.respond_to?(:force_encoding)

from geoip.

cjheath avatar cjheath commented on July 30, 2024

Apologies for the delay releasing this fix. I had introduced a breaking change and not had time to diagnose it. The gem is now released as 1.5.0

from geoip.

epitron avatar epitron commented on July 30, 2024

Thanks!

from geoip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.