Skip to content

Commit 1b0051d

Browse files
committed
Merge branch '11.x' into 12.x
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
2 parents 23b327d + b6f2ea6 commit 1b0051d

File tree

3 files changed

+91
-25
lines changed

3 files changed

+91
-25
lines changed

src/Illuminate/Console/Application.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ public function output()
205205
: '';
206206
}
207207

208+
/**
209+
* Add an array of commands to the console.
210+
*
211+
* @param array<int, \Symfony\Component\Console\Command\Command> $commands
212+
* @return void
213+
*/
214+
#[\Override]
215+
public function addCommands(array $commands): void
216+
{
217+
foreach ($commands as $command) {
218+
$this->add($command);
219+
}
220+
}
221+
208222
/**
209223
* Add a command to the console.
210224
*

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,14 @@ public function validateBetween($attribute, $value, $parameters)
471471
{
472472
$this->requireParameterCount(2, $parameters, 'between');
473473

474-
return with(
475-
BigNumber::of($this->getSize($attribute, $value)),
476-
fn ($size) => $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1]))
477-
);
474+
try {
475+
return with(
476+
BigNumber::of($this->getSize($attribute, $value)),
477+
fn ($size) => $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1]))
478+
);
479+
} catch (MathException) {
480+
return false;
481+
}
478482
}
479483

480484
/**
@@ -1224,22 +1228,34 @@ public function validateGt($attribute, $value, $parameters)
12241228
$this->shouldBeNumeric($attribute, 'Gt');
12251229

12261230
if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) {
1227-
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThan($this->trim($parameters[0]));
1231+
try {
1232+
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThan($this->trim($parameters[0]));
1233+
} catch (MathException) {
1234+
return false;
1235+
}
12281236
}
12291237

12301238
if (is_numeric($parameters[0])) {
12311239
return false;
12321240
}
12331241

12341242
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
1235-
return BigNumber::of($this->trim($value))->isGreaterThan($this->trim($comparedToValue));
1243+
try {
1244+
return BigNumber::of($this->trim($value))->isGreaterThan($this->trim($comparedToValue));
1245+
} catch (MathException) {
1246+
return false;
1247+
}
12361248
}
12371249

12381250
if (! $this->isSameType($value, $comparedToValue)) {
12391251
return false;
12401252
}
12411253

1242-
return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue);
1254+
try {
1255+
return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue);
1256+
} catch (MathException) {
1257+
return false;
1258+
}
12431259
}
12441260

12451261
/**
@@ -1259,7 +1275,11 @@ public function validateLt($attribute, $value, $parameters)
12591275
$this->shouldBeNumeric($attribute, 'Lt');
12601276

12611277
if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) {
1262-
return BigNumber::of($this->getSize($attribute, $value))->isLessThan($this->trim($parameters[0]));
1278+
try {
1279+
return BigNumber::of($this->getSize($attribute, $value))->isLessThan($this->trim($parameters[0]));
1280+
} catch (MathException) {
1281+
return false;
1282+
}
12631283
}
12641284

12651285
if (is_numeric($parameters[0])) {
@@ -1274,7 +1294,11 @@ public function validateLt($attribute, $value, $parameters)
12741294
return false;
12751295
}
12761296

1277-
return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue);
1297+
try {
1298+
return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue);
1299+
} catch (MathException) {
1300+
return false;
1301+
}
12781302
}
12791303

12801304
/**
@@ -1294,22 +1318,34 @@ public function validateGte($attribute, $value, $parameters)
12941318
$this->shouldBeNumeric($attribute, 'Gte');
12951319

12961320
if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) {
1297-
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0]));
1321+
try {
1322+
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0]));
1323+
} catch (MathException) {
1324+
return false;
1325+
}
12981326
}
12991327

13001328
if (is_numeric($parameters[0])) {
13011329
return false;
13021330
}
13031331

13041332
if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) {
1305-
return BigNumber::of($this->trim($value))->isGreaterThanOrEqualTo($this->trim($comparedToValue));
1333+
try {
1334+
return BigNumber::of($this->trim($value))->isGreaterThanOrEqualTo($this->trim($comparedToValue));
1335+
} catch (MathException) {
1336+
return false;
1337+
}
13061338
}
13071339

13081340
if (! $this->isSameType($value, $comparedToValue)) {
13091341
return false;
13101342
}
13111343

1312-
return $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue);
1344+
try {
1345+
return $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue);
1346+
} catch (MathException) {
1347+
return false;
1348+
}
13131349
}
13141350

13151351
/**
@@ -1329,7 +1365,11 @@ public function validateLte($attribute, $value, $parameters)
13291365
$this->shouldBeNumeric($attribute, 'Lte');
13301366

13311367
if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) {
1332-
return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0]));
1368+
try {
1369+
return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0]));
1370+
} catch (MathException) {
1371+
return false;
1372+
}
13331373
}
13341374

13351375
if (is_numeric($parameters[0])) {
@@ -1344,7 +1384,11 @@ public function validateLte($attribute, $value, $parameters)
13441384
return false;
13451385
}
13461386

1347-
return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue);
1387+
try {
1388+
return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue);
1389+
} catch (MathException) {
1390+
return false;
1391+
}
13481392
}
13491393

13501394
/**
@@ -1579,7 +1623,11 @@ public function validateMax($attribute, $value, $parameters)
15791623
return false;
15801624
}
15811625

1582-
return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0]));
1626+
try {
1627+
return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0]));
1628+
} catch (MathException) {
1629+
return false;
1630+
}
15831631
}
15841632

15851633
/**
@@ -1681,7 +1729,11 @@ public function validateMin($attribute, $value, $parameters)
16811729
{
16821730
$this->requireParameterCount(1, $parameters, 'min');
16831731

1684-
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0]));
1732+
try {
1733+
return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0]));
1734+
} catch (MathException) {
1735+
return false;
1736+
}
16851737
}
16861738

16871739
/**
@@ -2501,7 +2553,11 @@ public function validateSize($attribute, $value, $parameters)
25012553
{
25022554
$this->requireParameterCount(1, $parameters, 'size');
25032555

2504-
return BigNumber::of($this->getSize($attribute, $value))->isEqualTo($this->trim($parameters[0]));
2556+
try {
2557+
return BigNumber::of($this->getSize($attribute, $value))->isEqualTo($this->trim($parameters[0]));
2558+
} catch (MathException) {
2559+
return false;
2560+
}
25052561
}
25062562

25072563
/**
@@ -2784,6 +2840,8 @@ protected function trim($value)
27842840
* @param string $attribute
27852841
* @param mixed $value
27862842
* @return mixed
2843+
*
2844+
* @throws \Illuminate\Support\Exceptions\MathException
27872845
*/
27882846
protected function ensureExponentWithinAllowedRange($attribute, $value)
27892847
{

tests/Validation/ValidationValidatorTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Illuminate\Database\Eloquent\Model;
1919
use Illuminate\Support\Arr;
2020
use Illuminate\Support\Carbon;
21-
use Illuminate\Support\Exceptions\MathException;
2221
use Illuminate\Support\Stringable;
2322
use Illuminate\Translation\ArrayLoader;
2423
use Illuminate\Translation\Translator;
@@ -9622,10 +9621,7 @@ public function testItLimitsLengthOfScientificNotationExponent($value)
96229621
$trans = $this->getIlluminateArrayTranslator();
96239622
$validator = new Validator($trans, ['foo' => $value], ['foo' => 'numeric|min:3']);
96249623

9625-
$this->expectException(MathException::class);
9626-
$this->expectExceptionMessage('Scientific notation exponent outside of allowed range.');
9627-
9628-
$validator->passes();
9624+
$this->assertFalse($validator->passes());
96299625
}
96309626

96319627
public static function outsideRangeExponents()
@@ -9680,10 +9676,8 @@ public function testItCanConfigureAllowedExponentRange()
96809676
$this->assertSame('1.0e-1000', $value);
96819677

96829678
$withinRange = false;
9683-
$this->expectException(MathException::class);
9684-
$this->expectExceptionMessage('Scientific notation exponent outside of allowed range.');
96859679

9686-
$validator->passes();
9680+
$this->assertFalse($validator->passes());
96879681
}
96889682

96899683
protected function getTranslator()

0 commit comments

Comments
 (0)