Fix db field overflow when copying a check with a long name

This commit is contained in:
Pēteris Caune 2020-12-03 13:01:53 +02:00
parent 9623e3eacb
commit 5d650f07fb
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 19 additions and 1 deletions

View File

@ -18,6 +18,9 @@ All notable changes to this project will be documented in this file.
- Implement badge mode (up/down vs up/late/down) selector (#282)
- Add Ping.exitstatus field, store client's reported exit status values (#455)
## Bug Fixes
- Fix db field overflow when copying a check with a long name
## v1.17.0 - 2020-10-14
## Improvements

View File

@ -41,3 +41,13 @@ class CopyCheckTestCase(BaseTestCase):
self.client.login(username="bob@example.org", password="password")
r = self.client.post(self.copy_url)
self.assertEqual(r.status_code, 403)
def test_it_handles_long_check_name(self):
self.check.name = "A" * 100
self.check.save()
self.client.login(username="alice@example.org", password="password")
self.client.post(self.copy_url)
q = Check.objects.filter(name="A" * 90 + "... (copy)")
self.assertTrue(q.exists())

View File

@ -623,8 +623,13 @@ def copy(request, code):
if check.project.num_checks_available() <= 0:
return HttpResponseBadRequest()
new_name = check.name + " (copy)"
# Make sure we don't exceed the 100 character db field limit:
if len(new_name) > 100:
new_name = check.name[:90] + "... (copy)"
copied = Check(project=check.project)
copied.name = check.name + " (copy)"
copied.name = new_name
copied.desc, copied.tags = check.desc, check.tags
copied.subject, copied.subject_fail = check.subject, check.subject_fail
copied.methods = check.methods