Parcourir la source

Fixes #544: Strip CRLF-style line terminators from rendered export templates

Jeremy Stretch il y a 8 ans
Parent
commit
99510a990a
1 fichiers modifiés avec 4 ajouts et 4 suppressions
  1. 4 4
      netbox/extras/models.py

+ 4 - 4
netbox/extras/models.py

@@ -234,10 +234,10 @@ class ExportTemplate(models.Model):
         """
         """
         template = Template(self.template_code)
         template = Template(self.template_code)
         mime_type = 'text/plain' if not self.mime_type else self.mime_type
         mime_type = 'text/plain' if not self.mime_type else self.mime_type
-        response = HttpResponse(
-            template.render(Context(context_dict)),
-            content_type=mime_type
-        )
+        output = template.render(Context(context_dict))
+        # Replace CRLF-style line terminators
+        output = output.replace('\r\n', '\n')
+        response = HttpResponse(output, content_type=mime_type)
         if self.file_extension:
         if self.file_extension:
             filename += '.{}'.format(self.file_extension)
             filename += '.{}'.format(self.file_extension)
         response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
         response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)