Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion netbox/utilities/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions netbox/utilities/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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


Expand Down Expand Up @@ -364,3 +365,16 @@ def test_csv_delimiters(self):
{'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 ")