kopia lustrzana https://github.com/wagtail/wagtail
Merge pull request #574 from kaedroho/issue/573
Prevent rendition filenames going over 60 chars (even with a large focal_point_key)pull/494/merge
commit
6369fb2f6b
|
@ -161,10 +161,9 @@ class AbstractImage(models.Model, TagSearchable):
|
|||
|
||||
input_filename_parts = os.path.basename(file_field.file.name).split('.')
|
||||
filename_without_extension = '.'.join(input_filename_parts[:-1])
|
||||
filename_without_extension = filename_without_extension[:60] # trim filename base so that we're well under 100 chars
|
||||
output_filename_parts = [filename_without_extension, focal_point_key, filter.spec] + input_filename_parts[-1:]
|
||||
output_filename = '.'.join(output_filename_parts)
|
||||
|
||||
extension = '.'.join([focal_point_key, filter.spec] + input_filename_parts[-1:])
|
||||
filename_without_extension = filename_without_extension[:(59-len(extension))] # Truncate filename to prevent it going over 60 chars
|
||||
output_filename = filename_without_extension + '.' + extension
|
||||
generated_image_file = File(generated_image, name=output_filename)
|
||||
|
||||
if self.focal_point:
|
||||
|
|
|
@ -32,7 +32,7 @@ from wagtail.tests.models import EventPage, EventPageCarouselItem
|
|||
from wagtail.wagtailcore.models import Page
|
||||
|
||||
|
||||
def get_test_image_file():
|
||||
def get_test_image_file(filename='test.png'):
|
||||
from six import BytesIO
|
||||
from PIL import Image
|
||||
from django.core.files.images import ImageFile
|
||||
|
@ -40,7 +40,7 @@ def get_test_image_file():
|
|||
f = BytesIO()
|
||||
image = Image.new('RGB', (640, 480), 'white')
|
||||
image.save(f, 'PNG')
|
||||
return ImageFile(f, name='test.png')
|
||||
return ImageFile(f, name=filename)
|
||||
|
||||
|
||||
Image = get_image_model()
|
||||
|
@ -1016,3 +1016,24 @@ class TestCropToPoint(TestCase):
|
|||
CropBox(125, 25, 275, 175),
|
||||
)
|
||||
|
||||
|
||||
class TestIssue573(TestCase):
|
||||
"""
|
||||
This tests for a bug which causes filename limit on Renditions to be reached
|
||||
when the Image has a long original filename and a big focal point key
|
||||
"""
|
||||
def test_issue_573(self):
|
||||
# Create an image with a big filename and focal point
|
||||
image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file('thisisaverylongfilename-abcdefghijklmnopqrstuvwxyz-supercalifragilisticexpialidocious.png'),
|
||||
focal_point_x=1000,
|
||||
focal_point_y=1000,
|
||||
focal_point_width=1000,
|
||||
focal_point_height=1000,
|
||||
)
|
||||
|
||||
# Try creating a rendition from that image
|
||||
# This would crash if the bug is present
|
||||
image.get_rendition('fill-800x600')
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue