From 76138f3080c6ceca71f884041183a46583002e8b Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 24 Feb 2020 13:29:00 -0500 Subject: [PATCH] Fixes #4222: Escape double quotes on encapsulated values during CSV export --- docs/release-notes/version-2.7.md | 1 + netbox/utilities/utils.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 35bf242f5..7781e4136 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -7,6 +7,7 @@ ## Bug Fixes * [#4221](https://github.com/netbox-community/netbox/issues/4221) - Fix exception when deleting a device with interface connections when an interfaces webhook is defined +* [#4222](https://github.com/netbox-community/netbox/issues/4222) - Escape double quotes on encapsulated values during CSV export * [#4224](https://github.com/netbox-community/netbox/issues/4224) - Fix display of rear device image if front image is not defined * [#4228](https://github.com/netbox-community/netbox/issues/4228) - Improve fit of device images in rack elevations * [#4230](https://github.com/netbox-community/netbox/issues/4230) - Fix rack units filtering on elevation endpoint diff --git a/netbox/utilities/utils.py b/netbox/utilities/utils.py index 6969a60e9..6bef3093c 100644 --- a/netbox/utilities/utils.py +++ b/netbox/utilities/utils.py @@ -31,8 +31,9 @@ def csv_format(data): if not isinstance(value, str): value = '{}'.format(value) - # Double-quote the value if it contains a comma + # Double-quote the value if it contains a comma or line break if ',' in value or '\n' in value: + value = value.replace('"', '""') # Escape double-quotes csv.append('"{}"'.format(value)) else: csv.append('{}'.format(value))