From 79bf12a8fe927c4107d6cef5202063c809613a22 Mon Sep 17 00:00:00 2001 From: Per von Zweigbergk Date: Mon, 18 Sep 2023 14:33:29 +0200 Subject: [PATCH] 13791 rename whitespace fix (#13793) * Add test for bug #13791 https://github.com/netbox-community/netbox/issues/13791 * Fix #13791 by disabling striping on find and replace fields of BulkRenameForm --- netbox/utilities/forms/forms.py | 5 ++++- netbox/utilities/tests/test_forms.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/forms/forms.py b/netbox/utilities/forms/forms.py index 9f84e100f..04d956a49 100644 --- a/netbox/utilities/forms/forms.py +++ b/netbox/utilities/forms/forms.py @@ -40,8 +40,11 @@ class BulkRenameForm(BootstrapMixin, forms.Form): """ An extendable form to be used for renaming objects in bulk. """ - find = forms.CharField() + find = forms.CharField( + strip=False + ) replace = forms.CharField( + strip=False, required=False ) use_regex = forms.BooleanField( diff --git a/netbox/utilities/tests/test_forms.py b/netbox/utilities/tests/test_forms.py index 8fd001ba8..d014d4bbd 100644 --- a/netbox/utilities/tests/test_forms.py +++ b/netbox/utilities/tests/test_forms.py @@ -3,6 +3,7 @@ from django.test import TestCase from utilities.choices import ImportFormatChoices from utilities.forms.bulk_import import BulkImportForm +from utilities.forms.forms import BulkRenameForm from utilities.forms.utils import expand_alphanumeric_pattern, expand_ipaddress_pattern @@ -364,3 +365,16 @@ class ImportFormTest(TestCase): {'a': '1', 'b': '2', 'c': '3'}, {'a': '4', 'b': '5', 'c': '6'}, ]) + + +class BulkRenameFormTest(TestCase): + def test_no_strip_whitespace(self): + # Tests to make sure Bulk Rename Form isn't stripping whitespaces + # See: https://github.com/netbox-community/netbox/issues/13791 + form = BulkRenameForm(data={ + "find": " hello ", + "replace": " world " + }) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data["find"], " hello ") + self.assertEqual(form.cleaned_data["replace"], " world ")