Skip to content

Commit

Permalink
More strict checking of addItem request for child repeaters (#4814)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ben Thomson authored and daftspunk committed Dec 12, 2019
1 parent 5839b68 commit c17cb58
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/backend/formwidgets/Repeater.php
Expand Up @@ -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',
Expand Down Expand Up @@ -404,15 +404,15 @@ protected function checkAddItemRequest()
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];
}
}
}

Expand Down

0 comments on commit c17cb58

Please sign in to comment.