From 18d9ecd0f4d98f9230b3747217cdc35ea69d60c2 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 1 Jun 2023 16:47:47 +1000 Subject: [PATCH] Tweak svg data cleaning: (#4941) - Decode data if passed as bytes --- InvenTree/InvenTree/sanitizer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/sanitizer.py b/InvenTree/InvenTree/sanitizer.py index a9f1fd2f3d..d417b85118 100644 --- a/InvenTree/InvenTree/sanitizer.py +++ b/InvenTree/InvenTree/sanitizer.py @@ -43,7 +43,7 @@ ALLOWED_ATTRIBUTES_SVG = [ ] -def sanitize_svg(file_data: str, strip: bool = True, elements: str = ALLOWED_ELEMENTS_SVG, attributes: str = ALLOWED_ATTRIBUTES_SVG) -> str: +def sanitize_svg(file_data, strip: bool = True, elements: str = ALLOWED_ELEMENTS_SVG, attributes: str = ALLOWED_ATTRIBUTES_SVG) -> str: """Sanatize a SVG file. Args: @@ -56,6 +56,10 @@ def sanitize_svg(file_data: str, strip: bool = True, elements: str = ALLOWED_ELE str: Sanitzied SVG file. """ + # Handle byte-encoded data + if type(file_data) == bytes: + file_data = file_data.decode('utf-8') + cleaned = clean( file_data, tags=elements, @@ -64,4 +68,5 @@ def sanitize_svg(file_data: str, strip: bool = True, elements: str = ALLOWED_ELE strip_comments=strip, css_sanitizer=CSSSanitizer() ) + return cleaned