Merge remote-tracking branch 'qubesos/pr/16'

* qubesos/pr/16:
  Fix off-by-one error in header length calculation
This commit is contained in:
Marek Marczykowski-Górecki 2017-08-12 14:02:51 +02:00
commit dd71f295e5
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 4 additions and 3 deletions

View File

@ -49,9 +49,9 @@ ICON_MAXSIZE = 512
# header consists of two decimal numbers, SPC and LF # header consists of two decimal numbers, SPC and LF
re_imghdr = re.compile(br'^\d+ \d+\n$') re_imghdr = re.compile(br'^\d+ \d+\n$')
imghdrlen = lambda w, h: int(math.ceil(math.log10(w)) \ def imghdrlen(w, h):
+ math.ceil(math.log10(h)) \ # width & height are inclusive max vals, and +2 for ' ' and '\n'
+ 2) return len(str(w)) + len(str(h)) + 2
class Image(object): class Image(object):
def __init__(self, rgba, size): def __init__(self, rgba, size):

View File

@ -54,6 +54,7 @@ class TestCaseImage(unittest.TestCase):
class TestCaseFunctionsAndConstants(unittest.TestCase): class TestCaseFunctionsAndConstants(unittest.TestCase):
def test_00_imghdrlen(self): def test_00_imghdrlen(self):
self.assertEqual(qubesimgconverter.imghdrlen(8, 15), len('8 15\n')) self.assertEqual(qubesimgconverter.imghdrlen(8, 15), len('8 15\n'))
self.assertEqual(qubesimgconverter.imghdrlen(100, 100), len('100 100\n'))
def test_01_re_imghdr(self): def test_01_re_imghdr(self):
self.assertTrue(qubesimgconverter.re_imghdr.match('8 15\n')) self.assertTrue(qubesimgconverter.re_imghdr.match('8 15\n'))