diff --git a/hc/api/schemas.py b/hc/api/schemas.py index 5f6acf05..75f05e96 100644 --- a/hc/api/schemas.py +++ b/hc/api/schemas.py @@ -4,7 +4,7 @@ check = { "type": "object", "properties": { "name": {"type": "string", "maxLength": 100}, - "slug": {"type": "string", "pattern": "^[a-zA-Z0-9-_]*$"}, + "slug": {"type": "string", "pattern": "^[a-z0-9-_]*$"}, "desc": {"type": "string"}, "tags": {"type": "string", "maxLength": 500}, "timeout": {"type": "number", "minimum": 60, "maximum": 31536000}, diff --git a/hc/api/tests/test_create_check.py b/hc/api/tests/test_create_check.py index e1e5066f..93bbe817 100644 --- a/hc/api/tests/test_create_check.py +++ b/hc/api/tests/test_create_check.py @@ -387,8 +387,9 @@ class CreateCheckTestCase(BaseTestCase): self.assertEqual(check.slug, "") def test_it_handles_invalid_slug(self): - r = self.post({"name": "Foo", "slug": "Hey!"}, v=3) - self.assertEqual(r.status_code, 400) - self.assertEqual( - r.json()["error"], "json validation error: slug does not match pattern" - ) + for slug in ["Uppercase", "special!", "look spaces"]: + r = self.post({"name": "Foo", "slug": "Hey!"}, v=3) + self.assertEqual(r.status_code, 400) + self.assertEqual( + r.json()["error"], "json validation error: slug does not match pattern" + ) diff --git a/static/js/slug-suggestions.js b/static/js/slug-suggestions.js index d874dd7f..cc41d5de 100644 --- a/static/js/slug-suggestions.js +++ b/static/js/slug-suggestions.js @@ -23,7 +23,7 @@ $(function () { if (suggested) { help.html(`Suggested value: <code>${suggested}</code>`); } else { - help.text("Allowed characters: a-z, A-Z, 0-9, hyphens, underscores."); + help.text("Allowed characters: a-z, 0-9, hyphens, underscores."); } btn.attr("disabled", !suggested); diff --git a/templates/front/add_check_modal.html b/templates/front/add_check_modal.html index 56e03238..e154fb20 100644 --- a/templates/front/add_check_modal.html +++ b/templates/front/add_check_modal.html @@ -40,7 +40,7 @@ type="text" maxlength="100" value="{{ check.slug }}" - pattern="[a-zA-Z0-9_-]+" + pattern="[a-z0-9_-]+" class="form-control" /> <span class="input-group-btn"> <button diff --git a/templates/front/update_name_modal.html b/templates/front/update_name_modal.html index dc4ebe37..1a123bbc 100644 --- a/templates/front/update_name_modal.html +++ b/templates/front/update_name_modal.html @@ -45,7 +45,7 @@ type="text" maxlength="100" value="{{ check.slug }}" - pattern="[a-zA-Z0-9_-]+" + pattern="[a-z0-9_-]+" data-src-id="update-name-input" data-btn-id="use-suggested" data-preview-id="slug-help"