Skip to content

Commit

Permalink
Fixed #21996 -- Used proper encoding for GeoIP content
Browse files Browse the repository at this point in the history
Thanks Florent Messa for the report.
  • Loading branch information
claudep committed Feb 10, 2014
1 parent c3dd38c commit fb1e343
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions django/contrib/gis/geoip/prototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GeoIPRecord(Structure):
('continent_code', c_char_p),
]
geoip_char_fields = [name for name, ctype in GeoIPRecord._fields_ if ctype is c_char_p]
GEOIP_DEFAULT_ENCODING = 'iso-8859-1'
geoip_encodings = {
0: 'iso-8859-1',
1: 'utf8',
Expand Down Expand Up @@ -100,7 +101,7 @@ def check_string(result, func, cargs):
free(result)
else:
s = ''
return s.decode()
return s.decode(GEOIP_DEFAULT_ENCODING)

GeoIP_database_info = lgeoip.GeoIP_database_info
GeoIP_database_info.restype = geoip_char_p
Expand All @@ -111,7 +112,7 @@ def check_string(result, func, cargs):
def string_output(func):
def _err_check(result, func, cargs):
if result:
return result.decode()
return result.decode(GEOIP_DEFAULT_ENCODING)
return result
func.restype = c_char_p
func.errcheck = _err_check
Expand Down
2 changes: 2 additions & 0 deletions django/contrib/gis/geoip/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ def test05_unicode_response(self):
g = GeoIP()
d = g.city("www.osnabrueck.de")
self.assertEqual('Osnabrück', d['city'])
d = g.country('200.7.49.81')
self.assertEqual('Curaçao', d['country_name'])
4 changes: 3 additions & 1 deletion docs/releases/1.6.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Django 1.6.3 release notes
This is Django 1.6.3, a bugfix release for Django 1.6. Django 1.6.3 fixes
several bugs in 1.6.2:

* ...
* Content retrieved from the GeoIP library is now properly decoded from its
default ``iso-8859-1`` encoding
(`#21996 <http://code.djangoproject.com/ticket/21996>`_).

0 comments on commit fb1e343

Please sign in to comment.