From 4e773340cea13753bd7d2c191f38a503fee8a124 Mon Sep 17 00:00:00 2001 From: Wolfgang Ginolas Date: Mon, 26 Jun 2023 09:17:50 +0200 Subject: [PATCH] Diagrams: Pass numbers as numbers to chainpad https://github.com/cryptpad/cryptpad/issues/1063 --- www/diagram/inner.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/www/diagram/inner.js b/www/diagram/inner.js index 0949a31c0..e895227ff 100644 --- a/www/diagram/inner.js +++ b/www/diagram/inner.js @@ -83,9 +83,24 @@ define([ }); }; + const numbersToNumbers = function(o) { + const type = typeof o; + + if (type === "object") { + for (const key in o) { + o[key] = numbersToNumbers(o[key]); + } + return o; + } else if (type === 'string' && o.match(/^[+-]?(0|(([1-9]\d*)(\.\d+)?))$/)) { + return parseFloat(o, 10); + } else { + return o; + } + } + const xmlAsJsonContent = (xml) => { var decompressedXml = decompressDrawioXml(xml); - return x2js.xml2js(decompressedXml); + return numbersToNumbers(x2js.xml2js(decompressedXml)); }; var onDrawioChange = function(newXml) {