validate path prefix in form cleaning process to ensure proper formatting and prevent invalid characters

This commit is contained in:
Eduardo Silva
2026-03-16 20:23:05 -03:00
parent a9bfcac771
commit ebbffca21d

View File

@@ -277,3 +277,17 @@ class ApplicationRouteForm(forms.ModelForm):
css_class='row'
)
)
def clean(self):
cleaned_data = super().clean()
path_prefix = (cleaned_data.get('path_prefix') or '').strip()
if path_prefix:
if not path_prefix.startswith('/'):
self.add_error('path_prefix', _('Path prefix must start with /.'))
elif ' ' in path_prefix:
self.add_error('path_prefix', _('Path prefix cannot contain spaces.'))
elif any(c in path_prefix for c in ('{', '}', '\n', '\r')):
self.add_error('path_prefix', _('Path prefix contains invalid characters.'))
else:
cleaned_data['path_prefix'] = path_prefix
return cleaned_data