mirror of
https://github.com/pretix/pretix.git
synced 2026-05-20 17:44:02 +00:00
Compare commits
1 Commits
order-prin
...
fix-mail-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb61bcdd4e |
@@ -749,20 +749,39 @@ class MailSettingsPreview(EventPermissionRequiredMixin, View):
|
|||||||
if preview_item not in MailSettingsForm.base_context:
|
if preview_item not in MailSettingsForm.base_context:
|
||||||
return HttpResponseBadRequest(_('invalid item'))
|
return HttpResponseBadRequest(_('invalid item'))
|
||||||
|
|
||||||
regex = r"^" + re.escape(preview_item) + r"_(?P<idx>[\d]+)$"
|
re_escape_single_bracket = r"((\{)[^\}]+\{|\}[^\{]+(\})|(\{)[^\}]*$|^[^\{]*(\}))"
|
||||||
msgs = {}
|
msgs = {}
|
||||||
for k, v in request.POST.items():
|
for k, v in request.POST.items():
|
||||||
# only accept allowed fields
|
# only accept allowed fields
|
||||||
matched = re.search(regex, k)
|
if not k.startswith(preview_item + "_"):
|
||||||
if matched is not None:
|
continue
|
||||||
idx = matched.group('idx')
|
idx = k[len(preview_item)+1:]
|
||||||
if idx in self.supported_locale:
|
if idx in self.supported_locale:
|
||||||
|
cleaned_v = ""
|
||||||
|
test_v = v.replace("{{", "__").replace("}}", "__")
|
||||||
|
while True:
|
||||||
|
match = re.search(re_escape_single_bracket, test_v)
|
||||||
|
if not match:
|
||||||
|
cleaned_v += v
|
||||||
|
break
|
||||||
|
if "{" in match.groups():
|
||||||
|
# replace first occurrence of { with {{, but keep trailing { in testing string
|
||||||
|
match_end = match.end()-1
|
||||||
|
cleaned_v += v[:match_end].replace("{", "{{", 1)
|
||||||
|
else:
|
||||||
|
# replace last occurrence of } with }}
|
||||||
|
match_end = match.end()
|
||||||
|
cleaned_v += "}}".join(v[:match_end].rsplit("}", 1))
|
||||||
|
|
||||||
|
v = v[match_end:]
|
||||||
|
test_v = test_v[match_end:]
|
||||||
|
|
||||||
with language(self.supported_locale[idx], self.request.event.settings.region):
|
with language(self.supported_locale[idx], self.request.event.settings.region):
|
||||||
if k.startswith('mail_subject_'):
|
if k.startswith('mail_subject_'):
|
||||||
msgs[self.supported_locale[idx]] = format_map(bleach.clean(v), self.placeholders(preview_item))
|
msgs[self.supported_locale[idx]] = format_map(bleach.clean(cleaned_v), self.placeholders(preview_item))
|
||||||
else:
|
else:
|
||||||
msgs[self.supported_locale[idx]] = markdown_compile_email(
|
msgs[self.supported_locale[idx]] = markdown_compile_email(
|
||||||
format_map(v, self.placeholders(preview_item))
|
format_map(cleaned_v, self.placeholders(preview_item))
|
||||||
)
|
)
|
||||||
|
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
|
|||||||
Reference in New Issue
Block a user