Skip to content

Commit 146856f

Browse files
MillyAUTOMATIC1111
authored andcommitted
images: allow nested bracket in filename pattern
1 parent c7af69f commit 146856f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

modules/images.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def resize(im, w, h):
277277
invalid_filename_prefix = ' '
278278
invalid_filename_postfix = ' .'
279279
re_nonletters = re.compile(r'[\s' + string.punctuation + ']+')
280-
re_pattern = re.compile(r"([^\[\]]+|\[([^]]+)]|[\[\]]*)")
280+
re_pattern = re.compile(r"(.*?)(?:\[([^\[\]]+)\]|$)")
281281
re_pattern_arg = re.compile(r"(.*)<([^>]*)>$")
282282
max_filename_part_length = 128
283283

@@ -362,9 +362,9 @@ def apply(self, x):
362362

363363
for m in re_pattern.finditer(x):
364364
text, pattern = m.groups()
365+
res += text
365366

366367
if pattern is None:
367-
res += text
368368
continue
369369

370370
pattern_args = []
@@ -385,12 +385,9 @@ def apply(self, x):
385385
print(f"Error adding [{pattern}] to filename", file=sys.stderr)
386386
print(traceback.format_exc(), file=sys.stderr)
387387

388-
if replacement is None:
389-
res += f'[{pattern}]'
390-
else:
388+
if replacement is not None:
391389
res += str(replacement)
392-
393-
continue
390+
continue
394391

395392
res += f'[{pattern}]'
396393

0 commit comments

Comments
 (0)