From c17cb58aa121d06174f93ce5024a7946fb774dd9 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Thu, 12 Dec 2019 18:44:10 +0800 Subject: [PATCH] More strict checking of addItem request for child repeaters (#4814) Similarly named repeater fields being used in viewBag variables were being assigned aliases which succeeded the `strpos` check on line 407. This will more clearly look for a child repeater form and index. Fixes #4808 --- modules/backend/formwidgets/Repeater.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index e25df461f..f9fa3a6fb 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -98,7 +98,7 @@ class Repeater extends FormWidgetBase public function init() { $this->prompt = Lang::get('backend::lang.repeater.add_new_item'); - + $this->fillFromConfig([ 'form', 'prompt', @@ -404,15 +404,15 @@ class Repeater extends FormWidgetBase if ($this->alias === $widgetName) { // This repeater has made the AJAX request self::$onAddItemCalled = true; - } else if (strpos($widgetName, $this->alias) === 0) { + } else if (strpos($widgetName, $this->alias . 'Form') === 0) { // A child repeater has made the AJAX request // Get index from AJAX handler $handlerSuffix = str_replace($this->alias . 'Form', '', $widgetName); - preg_match('/^[0-9]+/', $handlerSuffix, $matches); - - $this->childAddItemCalled = true; - $this->childIndexCalled = (int) $matches[0]; + if (preg_match('/^[0-9]+/', $handlerSuffix, $matches)) { + $this->childAddItemCalled = true; + $this->childIndexCalled = (int) $matches[0]; + } } }