Skip to content

Commit be47ca9

Browse files
committed
fix: set default values for max filename length and random suffix in _ensure_safe_length
1 parent bb08f29 commit be47ca9

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

filer/utils/files.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def slugify(string):
123123
return slugify_django(force_str(string))
124124

125125

126-
def _ensure_safe_length(filename, max_length=None, random_suffix_length=None):
126+
def _ensure_safe_length(filename, max_length=155, random_suffix_length=16):
127127
"""
128128
Ensures that the filename does not exceed the maximum allowed length.
129129
If it does, the function truncates the filename and appends a random hexadecimal
@@ -142,9 +142,6 @@ def _ensure_safe_length(filename, max_length=None, random_suffix_length=None):
142142
Reference issue: https://github.com/django-cms/django-filer/issues/1270
143143
"""
144144

145-
max_length = max_length or getattr(settings, "FILER_MAX_FILENAME_LENGTH", 255)
146-
random_suffix_length = random_suffix_length or getattr(settings, "FILER_RANDOM_SUFFIX_LENGTH", 16)
147-
148145
if len(filename) <= max_length:
149146
return filename
150147

tests/test_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def setUp(self):
1111
"""
1212
Set up the test case by reading the configuration settings for the maximum filename length.
1313
"""
14-
self.max_length = getattr(settings, "FILER_MAX_FILENAME_LENGTH", 255)
15-
self.random_suffix_length = getattr(settings, "FILER_RANDOM_SUFFIX_LENGTH", 16)
14+
self.max_length = 155
15+
self.random_suffix_length = 16
1616

1717
def test_short_filename_remains_unchanged(self):
1818
"""
@@ -69,7 +69,7 @@ def test_edge_case_exact_length(self):
6969
Test that a filename exactly at the maximum allowed length remains unchanged.
7070
"""
7171
extension = ".png"
72-
base_length = 255 - len(extension)
72+
base_length = 155 - len(extension)
7373
base = "b" * base_length
7474
original = f"{base}{extension}"
7575
result = get_valid_filename(original)

0 commit comments

Comments
 (0)