Skip to content

Commit 214b1e0

Browse files
committed
Be more strict when chartering a new group, only accept [a-z][a-z0-9]+
as acronym (specifically not hyphens), closes ietf-tools#1080. - Legacy-Id: 5965
1 parent 52cefc5 commit 214b1e0

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

ietf/wginfo/edit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def clean_acronym(self):
6262
if self.wg and acronym == self.wg.acronym:
6363
return acronym # no change, no check
6464

65-
if not re.match(r'^[-a-z0-9]+$', acronym):
66-
raise forms.ValidationError("Acronym is invalid, may only contain letters, numbers and dashes.")
65+
if not re.match(r'^[a-z][a-z0-9]+$', acronym):
66+
raise forms.ValidationError("Acronym is invalid, must be at least two characters and only contain lowercase letters and numbers starting with a letter.")
6767

6868
existing = Group.objects.filter(acronym__iexact=acronym)
6969
if existing:

ietf/wginfo/tests.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,39 @@ def test_create(self):
100100

101101
num_wgs = len(Group.objects.filter(type="wg"))
102102

103+
bof_state = GroupStateName.objects.get(slug="bof")
104+
103105
# normal get
104106
r = self.client.get(url)
105107
self.assertEquals(r.status_code, 200)
106108
q = PyQuery(r.content)
107109
self.assertEquals(len(q('form input[name=acronym]')), 1)
108-
110+
109111
# faulty post
110112
r = self.client.post(url, dict(acronym="foobarbaz")) # No name
111113
self.assertEquals(r.status_code, 200)
112114
q = PyQuery(r.content)
113115
self.assertTrue(len(q('form ul.errorlist')) > 0)
114116
self.assertEquals(len(Group.objects.filter(type="wg")), num_wgs)
115117

118+
# acronym contains non-alphanumeric
119+
r = self.client.post(url, dict(acronym="test...", name="Testing WG", state=bof_state.pk))
120+
self.assertEquals(r.status_code, 200)
121+
122+
# acronym contains hyphen
123+
r = self.client.post(url, dict(acronym="test-wg", name="Testing WG", state=bof_state.pk))
124+
self.assertEquals(r.status_code, 200)
125+
126+
# acronym too short
127+
r = self.client.post(url, dict(acronym="t", name="Testing WG", state=bof_state.pk))
128+
self.assertEquals(r.status_code, 200)
129+
130+
# acronym doesn't start with an alpha character
131+
r = self.client.post(url, dict(acronym="1startwithalpha", name="Testing WG", state=bof_state.pk))
132+
self.assertEquals(r.status_code, 200)
133+
116134
# creation
117-
state = GroupStateName.objects.get(slug="bof")
118-
r = self.client.post(url, dict(acronym="testwg", name="Testing WG", state=state.pk))
135+
r = self.client.post(url, dict(acronym="testwg", name="Testing WG", state=bof_state.pk))
119136
self.assertEquals(r.status_code, 302)
120137
self.assertEquals(len(Group.objects.filter(type="wg")), num_wgs + 1)
121138
group = Group.objects.get(acronym="testwg")

0 commit comments

Comments
 (0)