From 70a20b3e8c2ae5a82765f7c0310f6124e7e87f25 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Sat, 21 Mar 2020 20:20:40 +0000 Subject: [PATCH] Basic regex validation on community rule entry form. Fixes #2928. Commit ready for merge. - Legacy-Id: 17490 --- ietf/community/forms.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ietf/community/forms.py b/ietf/community/forms.py index 1677c950c..f5aabf2ae 100644 --- a/ietf/community/forms.py +++ b/ietf/community/forms.py @@ -4,6 +4,8 @@ from __future__ import absolute_import, print_function, unicode_literals +import re + from django import forms from django.db.models import Q @@ -94,7 +96,12 @@ class SearchRuleForm(forms.ModelForm): f.required = True def clean_text(self): - return self.cleaned_data["text"].strip().lower() # names are always lower case + candidate_text = self.cleaned_data["text"].strip().lower() # names are always lower case + try: + re.compile(candidate_text) + except re.error as e: + raise forms.ValidationError(str(e)) + return candidate_text class SubscriptionForm(forms.ModelForm):