From c554443a6a724dd2d0f445a6c0eab26037d46f4a Mon Sep 17 00:00:00 2001 From: Per von Zweigbergk Date: Tue, 5 Sep 2023 10:33:21 +0200 Subject: [PATCH] Fix detection of YAML and JSON files with leading whitespace --- netbox/utilities/forms/bulk_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox/utilities/forms/bulk_import.py b/netbox/utilities/forms/bulk_import.py index b9022ce25..be90db3a1 100644 --- a/netbox/utilities/forms/bulk_import.py +++ b/netbox/utilities/forms/bulk_import.py @@ -81,12 +81,12 @@ class BulkImportForm(BootstrapMixin, SyncedDataMixin, forms.Form): Attempt to automatically detect the format (CSV, JSON, or YAML) of the given data, or raise a ValidationError. """ + first_line = data.strip().split('\n', 1)[0] try: - if data[0] in ('{', '['): + if first_line[0] in ('{', '['): return ImportFormatChoices.JSON - if data.startswith('---') or data.startswith('- '): + if first_line.startswith('---') or first_line.startswith('- '): return ImportFormatChoices.YAML - first_line = data.split('\n', 1)[0] if ',' in first_line: return ImportFormatChoices.CSV if ';' in first_line: