Skip to content

Commit 8f17b5c

Browse files
committed
Validate that name does not contain spaces on it
1 parent eeff9cb commit 8f17b5c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

readthedocs/projects/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,4 +796,8 @@ def clean_name(self):
796796
raise forms.ValidationError(
797797
_('There is already a variable with this name for this project'),
798798
)
799+
elif ' ' in name:
800+
raise forms.ValidationError(
801+
_("Variable name can't contain spaces"),
802+
)
799803
return name

readthedocs/rtd_tests/tests/test_project_forms.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,17 @@ def setUp(self):
487487
self.project = get(Project)
488488

489489
def test_use_invalid_names(self):
490+
data = {
491+
'name': 'VARIABLE WITH SPACES',
492+
'value': 'string here',
493+
}
494+
form = EnvironmentVariableForm(data, project=self.project)
495+
self.assertFalse(form.is_valid())
496+
self.assertIn(
497+
"Variable name can't contain spaces",
498+
form.errors['name'],
499+
)
500+
490501
data = {
491502
'name': 'READTHEDOCS__INVALID',
492503
'value': 'string here',
@@ -497,6 +508,7 @@ def test_use_invalid_names(self):
497508
"Variable name can't start with READTHEDOCS",
498509
form.errors['name'],
499510
)
511+
500512
data = {
501513
'name': '__INVALID',
502514
'value': 'string here',

0 commit comments

Comments
 (0)