Validate websocket JSON before sending

The default json library in python will send infinity values as `Infinity` as described [here](https://docs.python.org/3/library/json.html#json.dump).  Check that the JSON is strictly valid before sending it, otherwise throw an exception.

This fixes #3875
This commit is contained in:
Eyal authored and GitHub committed 2020-12-10 21:30:10 -07:00
1 parent e46e8fa17a
commit 7046bb9f15
1 file changed
+3
+3
View File
@@ -589,6 +589,9 @@ class PrinterStateConnection(
def _do_emit(self, type, payload):
try:
import json
_ = json.dumps(octoprint.util.thaw_frozendict({type: payload}), allow_nan=False)
self.send({type: payload})
except Exception as e:
if self._logger.isEnabledFor(logging.DEBUG):