Comments (6)
The encoding of the database file has not changed. The strings are stored internally as ISO-8859-1.
from geoip.
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.
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.
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.
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.
Thanks!
from geoip.
Related Issues (20)
- GeoIP.asn incorrect parsing of some records HOT 4
- Doesn't work with recent version of db HOT 2
- IP2Location LITE Support HOT 2
- Not supported with Maxmind GeoIP2 Country HOT 4
- Include CHANGELOG file to this gem HOT 2
- MMDB format will be supported in furture? HOT 1
- Errno::ENOENT: No such file or directory @ rb_sysopen - GeoIP.dat HOT 2
- Release 1.6 HOT 6
- utf-8 read incorrect HOT 1
- dnsmasq HOT 1
- Very weird bug. Sometime GEO_IP_CITY.city returns incorrect info HOT 1
- .each method always returns empty Enumerable for GeoIPCity.dat database HOT 10
- Missing Hash Outputs for different lookups
- missing 1.6.3 version tag in GitHub HOT 4
- Why is the latitude/longitude an empty string? HOT 1
- DATA_DIR incompatible with kali-rolling HOT 1
- Version unclear HOT 1
- GeoLite Legacy databases are now discontinued HOT 13
- test/csvORG2dat.py does not support python3 HOT 1
- Reporting Abuse on GeoIP HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geoip.