Handle unexpected strings properly (bug 826534)

This commit is contained in:
Matt Basta 2013-01-03 19:52:43 -05:00
Родитель aa36f6f434
Коммит b07a9935eb
2 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -101,7 +101,11 @@ def try_get_resource(err, package, url, filename, resource_type="URL",
filename=filename)
return
request.raw.close()
try:
request.raw.close()
except AttributeError:
# Some versions of requests don't support close().
pass
if not data:
generic_http_error()
@ -142,6 +146,12 @@ def try_get_resource(err, package, url, filename, resource_type="URL",
def test_icon(err, data, url, size):
try:
size = int(size)
except ValueError:
# This is handled elsewhere.
return
try:
icon = Image.open(data)
icon.verify()
@ -193,6 +203,13 @@ def test_app_resources(err, package):
icon_urls = set()
icons = manifest.get("icons", {}).items()
for icon_size, url in icons:
try:
icon_size = int(icon_size)
except ValueError:
# There will be an error for this someplace else.
continue
# Don't test the same icon URL twice.
if url in icon_urls:
continue

Просмотреть файл

@ -273,6 +273,9 @@ class TestIconProperties(TestCase):
self._test_icon("icon-128.png", 128)
self.assert_silent()
self._test_icon("icon-128.png", "128")
self.assert_silent()
def test_bad_icon(self):
self._test_icon("corrupt.xpi", 128)
self.assert_failed(with_errors=True)
@ -281,6 +284,10 @@ class TestIconProperties(TestCase):
self._test_icon("icon-128x64.png", 128)
self.assert_failed(with_errors=True)
self.setup_err()
self._test_icon("icon-128x64.png", "128")
self.assert_failed(with_errors=True)
def test_bad_size(self):
self._test_icon("icon-128.png", 256)
self.assert_failed(with_errors=True)