diff libervia/server/pages.py @ 1304:70e3341d25bf

pages: take care of None/null when exposing a variable
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:08:50 +0200
parents 04e7dd6b6f4d
children db9ea167c409
line wrap: on
line diff
--- a/libervia/server/pages.py	Thu Jul 16 09:08:50 2020 +0200
+++ b/libervia/server/pages.py	Thu Jul 16 09:08:50 2020 +0200
@@ -554,7 +554,11 @@
         template_data = request.template_data
         scripts = template_data.setdefault("scripts", utils.OrderedSet())
         for name, value in kwargs.items():
-            scripts.add(Script(content=f"var {name}={value!r};"))
+            if value is None:
+                value = "null"
+            else:
+                value = repr(value)
+            scripts.add(Script(content=f"var {name}={value};"))
 
     def registerURI(self, uri_tuple, get_uri_cb):
         """Register a URI handler