From 9bc76156799faf140494e9298b41c2f4acfa0e0c Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 15 Mar 2012 10:29:55 +0100 Subject: Fix undefined_to_string to accept empty strings. --- src/pyexiv2/utils.py | 4 +++- test/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pyexiv2/utils.py b/src/pyexiv2/utils.py index 0325699..95c3921 100644 --- a/src/pyexiv2/utils.py +++ b/src/pyexiv2/utils.py @@ -2,7 +2,7 @@ # ****************************************************************************** # -# Copyright (C) 2006-2011 Olivier Tilloy +# Copyright (C) 2006-2012 Olivier Tilloy # # This file is part of the pyexiv2 distribution. # @@ -148,6 +148,8 @@ def undefined_to_string(undefined): :return: the corresponding decoded string :rtype: string """ + if undefined == '': + return '' return ''.join(map(lambda x: chr(int(x)), undefined.rstrip().split(' '))) diff --git a/test/utils.py b/test/utils.py index 0b55254..cdff0d2 100644 --- a/test/utils.py +++ b/test/utils.py @@ -2,7 +2,7 @@ # ****************************************************************************** # -# Copyright (C) 2010 Olivier Tilloy +# Copyright (C) 2010-2012 Olivier Tilloy # # This file is part of the pyexiv2 distribution. # @@ -36,7 +36,7 @@ class TestConversions(unittest.TestCase): def test_undefined_to_string(self): self.assertEqual(undefined_to_string("48 50 50 49"), "0221") self.assertEqual(undefined_to_string("48 50 50 49 "), "0221") - self.assertRaises(ValueError, undefined_to_string, "") + self.assertEqual(undefined_to_string(""), "") self.assertRaises(ValueError, undefined_to_string, "foo") self.assertRaises(ValueError, undefined_to_string, "48 50 50 49") -- cgit