Skip to content

Commit

Permalink
Fix UTF-8 issue with format (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf authored Oct 25, 2016
1 parent e3c8c61 commit 47b7277
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions alibuild_helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def validateSpec(spec):
raise SpecError("Missing package field in header.")

def format(s, **kwds):
if type(s) == bytes:
s = s.decode()
return s % kwds

def doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
from alibuild_helpers.utilities import doDetectArch
from alibuild_helpers.utilities import Hasher
from alibuild_helpers.utilities import format

UBUNTU_1510_OS_RELEASE = """
NAME="Ubuntu"
Expand Down Expand Up @@ -129,6 +130,11 @@ def test_UTF8_Hasher(self):
self.assertEqual(h3.hexdigest(), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
self.assertNotEqual(h1.hexdigest(), h2.hexdigest())

def test_format(self):
self.assertEqual(format("%(foo)s", foo="foo"), "foo")
self.assertEqual(format(b"%(foo)s", foo="foo"), "foo")
self.assertRaises(KeyError, format, "%(foo)s", bar="foo")

if __name__ == '__main__':
unittest.main()

0 comments on commit 47b7277

Please sign in to comment.