Skip to content

Commit

Permalink
[BUGFIX] Prevent false migration from type input to type number
Browse files Browse the repository at this point in the history
An early return is added, in case the eval list doesn't contain neither
`int` nor `double`.

Fixes: #3923
  • Loading branch information
nhovratov authored and sabbelasichon committed Nov 20, 2023
1 parent 2736d8d commit 3e9263b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,25 @@ private function refactorColumn(DOMDocument $domDocument, ?DOMElement $configEle
return;
}

if (StringUtility::inList($evalListValue, self::INT) || StringUtility::inList($evalListValue, self::DOUBLE2)) {
$evalList = ArrayUtility::trimExplode(',', $evalListValue, true);

// Remove "int" from $evalList
$evalList = array_filter(
$evalList,
static fn (string $eval) => $eval !== self::INT && $eval !== self::DOUBLE2
);

if ($evalList !== []) {
// Write back filtered 'eval'
$evalDomElement->nodeValue = '';
$evalDomElement->appendChild($domDocument->createTextNode(implode(',', $evalList)));
} elseif ($evalDomElement->parentNode instanceof DOMElement) {
// 'eval' is empty, remove whole configuration
$evalDomElement->parentNode->removeChild($evalDomElement);
}
if (! StringUtility::inList($evalListValue, self::INT) && ! StringUtility::inList($evalListValue, self::DOUBLE2)) {
return;
}

$evalList = ArrayUtility::trimExplode(',', $evalListValue, true);

// Remove "int" from $evalList
$evalList = array_filter(
$evalList,
static fn (string $eval) => $eval !== self::INT && $eval !== self::DOUBLE2
);

if ($evalList !== []) {
// Write back filtered 'eval'
$evalDomElement->nodeValue = '';
$evalDomElement->appendChild($domDocument->createTextNode(implode(',', $evalList)));
} elseif ($evalDomElement->parentNode instanceof DOMElement) {
// 'eval' is empty, remove whole configuration
$evalDomElement->parentNode->removeChild($evalDomElement);
}

$toChangeItem = $this->extractDomElementByKey($configElement, 'type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,24 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void
return;
}

if (StringUtility::inList($evalListValue, self::INT) || StringUtility::inList($evalListValue, self::DOUBLE2)) {
$evalList = ArrayUtility::trimExplode(',', $evalListValue, true);

// Remove "int" from $evalList
$evalList = array_filter(
$evalList,
static fn (string $eval) => $eval !== self::INT && $eval !== self::DOUBLE2
);

if ($evalList !== []) {
// Write back filtered 'eval'
$evalArrayItem->value = new String_(implode(',', $evalList));
} else {
// 'eval' is empty, remove whole configuration
$this->removeNode($evalArrayItem);
}
if (! StringUtility::inList($evalListValue, self::INT) && ! StringUtility::inList($evalListValue, self::DOUBLE2)) {
return;
}

$evalList = ArrayUtility::trimExplode(',', $evalListValue, true);

// Remove "int" from $evalList
$evalList = array_filter(
$evalList,
static fn (string $eval) => $eval !== self::INT && $eval !== self::DOUBLE2
);

if ($evalList !== []) {
// Write back filtered 'eval'
$evalArrayItem->value = new String_(implode(',', $evalList));
} else {
// 'eval' is empty, remove whole configuration
$this->removeNode($evalArrayItem);
}

$toChangeArrayItem = $this->extractArrayItemByKey($configArray, 'type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<sheetTitle>sheetTitle</sheetTitle>
<type>array</type>
<el>
<settings.input_field>
<label>Input field</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</settings.input_field>
<settings.int_field>
<label>Int field</label>
<config>
Expand Down Expand Up @@ -39,6 +46,13 @@
<sheetTitle>sheetTitle</sheetTitle>
<type>array</type>
<el>
<settings.input_field>
<label>Input field</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</settings.input_field>
<settings.int_field>
<label>Int field</label>
<config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\MigrateEvalIntAndDouble2ToTyp
return [
'ctrl' => [],
'columns' => [
'non_int_field_with_eval_defined' => [
'label' => 'input field',
'config' => [
'type' => 'input',
'eval' => 'trim',
],
],
'int_field' => [
'label' => 'int field',
'config' => [
Expand Down Expand Up @@ -51,6 +58,13 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\MigrateEvalIntAndDouble2ToTyp
return [
'ctrl' => [],
'columns' => [
'non_int_field_with_eval_defined' => [
'label' => 'input field',
'config' => [
'type' => 'input',
'eval' => 'trim',
],
],
'int_field' => [
'label' => 'int field',
'config' => [
Expand Down

0 comments on commit 3e9263b

Please sign in to comment.