mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-24 14:53:45 +00:00
Fix bug where filenames with no extension cause an infinite loop
This commit is contained in:
parent
a108f16eff
commit
9c0968ad12
5 changed files with 39 additions and 1 deletions
|
|
@ -35,6 +35,7 @@ Changelog
|
|||
* Fix: Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
|
||||
* Fix: Non-text content is now preserved when adding or editing a link within rich text (Matt Westcott)
|
||||
* Fix: Fixed preview when `SECURE_SSL_REDIRECT = True` (Aymeric Augustin)
|
||||
* Fix: Prevent hang when truncating an image filename without an extension (Ricky Robinett)
|
||||
|
||||
|
||||
1.6.3 (30.09.2016)
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ Contributors
|
|||
* Stein Strindhaug
|
||||
* Žan Anderle
|
||||
* Mattias Loverot
|
||||
* Ricky Robinett
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ Bug fixes
|
|||
* Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
|
||||
* Non-text content is now preserved when adding or editing a link within rich text (Matt Westcott)
|
||||
* Fixed preview when ``SECURE_SSL_REDIRECT = True`` (Aymeric Augustin)
|
||||
* Prevent hang when truncating an image filename without an extension (Ricky Robinett)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
|||
|
|
@ -127,7 +127,10 @@ class AbstractImage(CollectionMember, index.Indexed, models.Model):
|
|||
# https://code.djangoproject.com/ticket/9893
|
||||
while len(os.path.join(folder_name, filename)) >= 95:
|
||||
prefix, dot, extension = filename.rpartition('.')
|
||||
filename = prefix[:-1] + dot + extension
|
||||
if prefix:
|
||||
filename = prefix[:-1] + dot + extension
|
||||
else:
|
||||
filename = extension[:-1]
|
||||
return os.path.join(folder_name, filename)
|
||||
|
||||
def get_usage(self):
|
||||
|
|
|
|||
|
|
@ -492,3 +492,35 @@ class TestIssue312(TestCase):
|
|||
height=rend1.height,
|
||||
focal_point_key=rend1.focal_point_key,
|
||||
)
|
||||
|
||||
|
||||
class TestFilenameReduction(TestCase):
|
||||
"""
|
||||
This tests for a bug which results in filenames without extensions
|
||||
causing an infinite loop
|
||||
"""
|
||||
def test_filename_reduction_no_ext(self):
|
||||
# Create an image with a big filename and no extension
|
||||
image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(
|
||||
'thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexpialidocioussuperlong'
|
||||
)
|
||||
)
|
||||
|
||||
# Saving file will result in infinite loop when bug is present
|
||||
image.save()
|
||||
self.assertEqual("original_images/thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexpiali", image.file.name)
|
||||
|
||||
# Test for happy path. Long filename with extension
|
||||
def test_filename_reduction_ext(self):
|
||||
# Create an image with a big filename and extensions
|
||||
image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(
|
||||
'thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexpialidocioussuperlong.png'
|
||||
)
|
||||
)
|
||||
|
||||
image.save()
|
||||
self.assertEqual("original_images/thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexp.png", image.file.name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue