From eb2e9d805004a4979400a4733d62b70600e76ca4 Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Thu, 10 Sep 2020 10:52:33 +0200 Subject: [PATCH] [ui][widgets][CodeMirrorFileWidget] Decode content read if bytes If the data returned by the read method of the object passed is byte, decode it. Otherwise the TextArea will just show it as is. --- beat/web/ui/widgets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beat/web/ui/widgets.py b/beat/web/ui/widgets.py index bafd9139d..79d05e5b8 100644 --- a/beat/web/ui/widgets.py +++ b/beat/web/ui/widgets.py @@ -346,6 +346,8 @@ class CodeMirrorFileWidget(CodeMirrorTextarea): contents = value elif hasattr(value, "read"): contents = value.read() + if type(contents) == bytes: + contents = contents.decode("utf-8") else: contents = "" return mark_safe(super().render(name, contents, attrs, renderer)) # nosec -- GitLab