From faba19e94cad715dac92ee27f5d9f2a96eea51d1 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 7 Jun 2025 13:56:20 +0200 Subject: [PATCH] matrix: sanitise quantity property (avoid error when NaN or < 0) --- CHANGELOG.md | 5 +++++ src/client/widgets/containers/matrix.js | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becc280f..d0543d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.29.6 + +- bug fixes + - matrix: prevent error when `quantity` is invalid + ## 1.29.5 - bug fixes diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index d4f83a5b..48d35d55 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -66,7 +66,9 @@ class Matrix extends Panel { if (parser.widgets[this.getProp('widgetType')]) { - for (let i = 0; i < this.getProp('quantity'); i++) { + var quantity = Math.max(parseInt(this.getProp('quantity')) || 0, 0) + + for (let i = 0; i < quantity; i++) { var props = deepCopy(this.getProp('props')[i]) var data = this.defaultProps(i) @@ -129,9 +131,12 @@ class Matrix extends Panel { case 'quantity': - if (oldPropValue > this.getProp('quantity')) { + var quantity = Math.max(parseInt(this.getProp('quantity')) || 0, 0) + oldPropValue = Math.max(parseInt(oldPropValue) || 0, 0) - for (let i = oldPropValue - 1; i >= this.getProp('quantity'); i--) { + if (oldPropValue > quantity) { + + for (let i = oldPropValue - 1; i >= quantity; i--) { if (this.widget.contains(this.children[i].container)) { this.widget.removeChild(this.children[i].container) } @@ -142,7 +147,7 @@ class Matrix extends Panel { this.cachedProps.props = this.resolveProp('props', undefined, true) - for (let i = oldPropValue; i < this.getProp('quantity'); i++) { + for (let i = oldPropValue; i < quantity; i++) { var props = deepCopy(this.getProp('props')[i]) var data = this.defaultProps(i) @@ -227,7 +232,7 @@ class Matrix extends Panel { propValue = propValue !== undefined ? propValue : this.props[propName] var data = [], - quantity = this.resolveProp('quantity', undefined, false, false, false) + quantity = Math.max(parseInt(this.resolveProp('quantity', undefined, false, false, false)) || 0, 0) if (typeof propValue === 'object' && propValue !== null && !Array.isArray(propValue)) { for (let i = 0; i < quantity; i++) {