Decode name from environment or from gecos with the locale's encoding and add

corresponding regression test; fixes handling of non-ascii developer name like
mine with e.g. syncpackage using it with dpkg-genchanges -e.
This commit is contained in:
Loïc Minier 2013-05-13 13:58:15 +02:00
parent bcdc6abbf8
commit 0aaa0f1f4a
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import re
import shlex
import socket
import sys
import locale
from ubuntutools.logger import Logger
@ -173,4 +174,9 @@ def ubu_email(name=None, email=None, export=True):
if export:
os.environ['DEBFULLNAME'] = name
os.environ['DEBEMAIL'] = email
# decode env var or gecos raw string with the current locale's encoding
encoding = locale.getdefaultlocale()[1]
if encoding:
name = name.decode(encoding)
return name, email

View File

@ -1,4 +1,5 @@
# test_config.py - Test suite for ubuntutools.config
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010, Stefano Rivera <stefanor@ubuntu.com>
#
@ -210,3 +211,8 @@ class UbuEmailTestCase(unittest.TestCase):
os.environ['DEBEMAIL'] = orig = '%s <%s>' % (name, email)
self.assertEqual(ubu_email(), (name, email))
self.assertEqual(os.environ['DEBEMAIL'], orig)
def test_unicode_name(self):
os.environ['DEBFULLNAME'] = name = 'Jöe Déveloper'
os.environ['DEBEMAIL'] = email = 'joe@example.net'
self.assertEqual(ubu_email(), (name.decode('utf-8'), email))