Skip to content

Commit 6de90ff

Browse files
Merge remote-tracking branch '39525/37919-cart-leadingzeros-issue' into comprv1
2 parents 0df0711 + d52ec01 commit 6de90ff

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento\Rule\Model\Condition;
87

98
use Magento\Framework\Data\Form;
@@ -866,6 +865,11 @@ public function validateAttribute($validatedValue)
866865
}
867866
}
868867
break;
868+
case '===':
869+
if (!is_array($validatedValue) && !is_array($value)) {
870+
$result = $this->_compareValues($validatedValue, $value);
871+
}
872+
break;
869873
}
870874

871875
if ('!=' == $option || '>' == $option || '<' == $option || '!{}' == $option || '!()' == $option) {
@@ -886,6 +890,10 @@ public function validateAttribute($validatedValue)
886890
protected function _compareValues($validatedValue, $value, $strict = true)
887891
{
888892
if ($strict && is_numeric($validatedValue) && is_numeric($value)) {
893+
$pattern = '/^0\d+$/';
894+
if (preg_match($pattern, $validatedValue) || preg_match($pattern, $value)) {
895+
return $validatedValue === $value;
896+
}
889897
return $validatedValue == $value;
890898
}
891899

app/code/Magento/Rule/Test/Unit/Model/Condition/AbstractConditionTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -65,6 +65,18 @@ public static function validateAttributeDataProvider()
6565
[null, '==', 0, false],
6666
[null, '==', 0.00, false],
6767

68+
// Test cases for strict equality with leading zeros
69+
['0123', '===', '123', false],
70+
['000123', '===', '123', false],
71+
['123', '===', '0123', false],
72+
['123', '===', '000123', false],
73+
['0123', '===', '0123', true],
74+
75+
// Test cases for strict equality with different numeric types
76+
[0123, '===', '0123', false],
77+
['123', '===', 0123, false],
78+
[0123, '===', 0123, true],
79+
6880
[1, '!=', 1, false],
6981
[0, '!=', 1, true],
7082
['0', '!=', 1, true],

0 commit comments

Comments
 (0)