Skip to content

Add validation for tags of length greater than 100 characters #4967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ class Meta(object):
widget=forms.Textarea,
)

def clean_tags(self):
tags = self.cleaned_data.get('tags', [])
for tag in tags:
if len(tag) > 100:
raise forms.ValidationError(
_('Length of each tag must be less than or equal to 100 characters.')
)
return tags


class ProjectAdvancedForm(ProjectTriggerBuildMixin, ProjectForm):

Expand Down
20 changes: 20 additions & 0 deletions readthedocs/rtd_tests/tests/test_project_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ def test_changing_vcs_should_not_change_latest_is_not_none(self):
latest.refresh_from_db()
self.assertEqual(latest.identifier, 'custom')

def test_length_of_tags(self):
data = {
'documentation_type': 'sphinx',
'language': 'en'
}
data['tags'] = '{},{}'.format('a'*50, 'b'*99)
form = ProjectExtraForm(data)
self.assertTrue(form.is_valid())

data['tags'] = '{},{}'.format('a'*90, 'b'*100)
form = ProjectExtraForm(data)
self.assertTrue(form.is_valid())

data['tags'] = '{},{}'.format('a'*99, 'b'*101)
form = ProjectExtraForm(data)
self.assertFalse(form.is_valid())
self.assertTrue(form.has_error('tags'))
error_msg = 'Length of each tag must be less than or equal to 100 characters.'
self.assertDictEqual(form.errors, {'tags': [error_msg]})


class TestProjectAdvancedForm(TestCase):

Expand Down