diff --git a/wagtail/wagtailadmin/forms.py b/wagtail/wagtailadmin/forms.py index fb1482413c..a036dd92ec 100644 --- a/wagtail/wagtailadmin/forms.py +++ b/wagtail/wagtailadmin/forms.py @@ -85,7 +85,7 @@ class CopyForm(forms.Form): super(CopyForm, self).__init__(*args, **kwargs) self.fields['new_title'] = forms.CharField(initial=self.page.title) - self.fields['new_slug'] = forms.CharField(initial=self.page.slug) + self.fields['new_slug'] = forms.SlugField(initial=self.page.slug) copy_subpages = forms.BooleanField(required=False, initial=True) publish_copies = forms.BooleanField(required=False, initial=True) diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 1df0f548bc..765c217866 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -1127,6 +1127,21 @@ class TestPageCopy(TestCase, WagtailTestUtils): # Check that a form error was raised self.assertFormError(response, 'form', 'new_slug', "This slug is already in use") + def test_page_copy_post_invalid_slug(self): + # Attempt to copy the page but set an invalid slug string + post_data = { + 'new_title': "Hello world 2", + 'new_slug': 'hello world!', + 'copy_subpages': False, + } + response = self.client.post(reverse('wagtailadmin_pages_copy', args=(self.test_page.id, )), post_data) + + # Should not be redirected (as the save should fail) + self.assertEqual(response.status_code, 200) + + # Check that a form error was raised + self.assertFormError(response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.") + def test_page_copy_no_publish_permission(self): # Turn user into an editor who can add pages but not publish them self.user.is_superuser = False