From 7e0921fb894d97990262290cdf508b095bc78c2a Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 21 Apr 2021 15:53:40 +0200 Subject: [PATCH] osc listener: only json-parse stringified objects/arrays/bool/null, not stringified primitives --- src/client/utils.js | 5 +++++ src/client/widgets/common/osc-receiver.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/utils.js b/src/client/utils.js index e4e06d67..ed688dbc 100644 --- a/src/client/utils.js +++ b/src/client/utils.js @@ -43,6 +43,11 @@ module.exports = { // ref in source: https://github.com/douglascrockford/JSON-js return ' \n+-eE{([0123456789tfn"'.indexOf(str[0]) !== -1 + }, + + isJSONObject: function(str) { + // same, but only for object/array/bool/null + return '{[tfn'.indexOf(str[0]) !== -1 } } diff --git a/src/client/widgets/common/osc-receiver.js b/src/client/widgets/common/osc-receiver.js index e5ed93f1..eb30e341 100644 --- a/src/client/widgets/common/osc-receiver.js +++ b/src/client/widgets/common/osc-receiver.js @@ -1,5 +1,5 @@ var osc = require('../../osc'), - {isJSON} = require('../../utils') + {isJSONObject} = require('../../utils') module.exports = class OscReceiver { @@ -7,7 +7,7 @@ module.exports = class OscReceiver { var {address, value, parent, propName, usePreArgs} = options - if (typeof value === 'string' && isJSON(value)) { + if (typeof value === 'string' && isJSONObject(value)) { try { this.value = JSON.parseFlex(value) } catch (err) { @@ -67,7 +67,7 @@ module.exports = class OscReceiver { } var value = args.slice(preArgs.length) if (value.length < 2) value = value[0] - if (typeof value === 'string' && isJSON(value)) { + if (typeof value === 'string' && isJSONObject(value)) { try { this.value = JSON.parseFlex(value) } catch (err) {