comparison libervia/web/server/pages.py @ 1630:1d1b1f360b75

server (pages): fix `expose_to_scripts` by dumping JSON: For whatever reason `expose_to_scripts` was doing a pseudo python/JS conversion itself and was only handling correctly `str` and `None`, while what is expected here is a JSON dump.
author Goffi <goffi@goffi.org>
date Thu, 26 Jun 2025 17:07:55 +0200
parents 5d9889f14012
children
comparison
equal deleted inserted replaced
1629:961468588131 1630:1d1b1f360b75
586 No check is done for conflicting name, use this carefully 586 No check is done for conflicting name, use this carefully
587 """ 587 """
588 template_data = request.template_data 588 template_data = request.template_data
589 scripts = template_data.setdefault("scripts", utils.OrderedSet()) 589 scripts = template_data.setdefault("scripts", utils.OrderedSet())
590 for name, value in kwargs.items(): 590 for name, value in kwargs.items():
591 if value is None: 591 value = json.dumps(value)
592 value = "null"
593 elif isinstance(value, str):
594 # FIXME: workaround for subtype used by python-dbus (dbus.String)
595 # to be removed when we get rid of python-dbus
596 value = repr(str(value))
597 else:
598 value = repr(value)
599 scripts.add(Script(content=f"var {name}={value};")) 592 scripts.add(Script(content=f"var {name}={value};"))
600 593
601 def register_uri(self, uri_tuple, get_uri_cb): 594 def register_uri(self, uri_tuple, get_uri_cb):
602 """Register a URI handler 595 """Register a URI handler
603 596