Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/code/Magento/Rule/Model/Condition/AbstractCondition.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

namespace Magento\Rule\Model\Condition;

use Magento\Framework\Data\Form;
Expand Down Expand Up @@ -866,6 +865,11 @@ public function validateAttribute($validatedValue)
}
}
break;
case '===':
if (!is_array($validatedValue) && !is_array($value)) {
$result = $this->_compareValues($validatedValue, $value);
}
break;
}

if ('!=' == $option || '>' == $option || '<' == $option || '!{}' == $option || '!()' == $option) {
Expand All @@ -886,6 +890,10 @@ public function validateAttribute($validatedValue)
protected function _compareValues($validatedValue, $value, $strict = true)
{
if ($strict && is_numeric($validatedValue) && is_numeric($value)) {
$pattern = '/^0\d+$/';
if (preg_match($pattern, $validatedValue) || preg_match($pattern, $value)) {
return $validatedValue === $value;
}
return $validatedValue == $value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2013 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -65,6 +65,18 @@ public static function validateAttributeDataProvider()
[null, '==', 0, false],
[null, '==', 0.00, false],

// Test cases for strict equality with leading zeros
['0123', '===', '123', false],
['000123', '===', '123', false],
['123', '===', '0123', false],
['123', '===', '000123', false],
['0123', '===', '0123', true],

// Test cases for strict equality with different numeric types
[0123, '===', '0123', false],
['123', '===', 0123, false],
[0123, '===', 0123, true],

[1, '!=', 1, false],
[0, '!=', 1, true],
['0', '!=', 1, true],
Expand Down