@@ -331,17 +331,17 @@ private function sanitizeReference(string $reference): string
331331 {
332332 // Remove HTML tags and potentially dangerous characters
333333 $ reference = strip_tags ($ reference );
334-
334+
335335 // Remove or encode special characters that could be used for XSS
336336 $ reference = htmlspecialchars ($ reference , ENT_QUOTES , 'UTF-8 ' );
337-
337+
338338 // Limit length to prevent buffer overflow attacks
339- $ reference = substr ($ reference , 0 , 255 );
340-
339+ $ reference = mb_substr ($ reference , 0 , 255 );
340+
341341 // Remove null bytes and control characters
342342 $ reference = preg_replace ('/[\x00-\x1F\x7F]/ ' , '' , $ reference );
343-
344- return trim ($ reference );
343+
344+ return mb_trim ($ reference ?? '' );
345345 }
346346
347347 /**
@@ -377,7 +377,7 @@ private function validateProductModel(): void
377377 if (str_contains ($ e ->getMessage (), 'must have a primary key ' )) {
378378 throw $ e ;
379379 }
380- throw new Exception ("Failed to validate product model ' {$ productModel }': " . $ e ->getMessage ());
380+ throw new Exception ("Failed to validate product model ' {$ productModel }': " . $ e ->getMessage (), $ e -> getCode (), $ e );
381381 }
382382 }
383383
@@ -390,22 +390,18 @@ private function validateDecimalPrecision(float $value): bool
390390 if ($ value > 99999999.99 ) {
391391 return false ;
392392 }
393-
393+
394394 // Check for too many decimal places (prevents precision attacks)
395395 $ decimalString = number_format ($ value , 10 , '. ' , '' );
396396 $ decimals = explode ('. ' , $ decimalString )[1 ] ?? '' ;
397- $ significantDecimals = rtrim ($ decimals , '0 ' );
398-
399- if (strlen ($ significantDecimals ) > 2 ) {
397+ $ significantDecimals = mb_rtrim ($ decimals , '0 ' );
398+
399+ if (mb_strlen ($ significantDecimals ) > 2 ) {
400400 return false ;
401401 }
402-
402+
403403 // Check for negative infinity, positive infinity, or NaN
404- if (!is_finite ($ value )) {
405- return false ;
406- }
407-
408- return true ;
404+ return is_finite ($ value );
409405 }
410406
411407 /**
@@ -416,8 +412,9 @@ private function validateDecimalPrecision(float $value): bool
416412 private function validateProduct (int $ productId ): bool
417413 {
418414 $ this ->validateProductModel ();
419-
415+
420416 $ productModel = config ('fifo.product_model ' );
417+
421418 /** @var class-string<Model> $productModel */
422419 return $ productModel ::query ()->where ('id ' , $ productId )->exists ();
423420 }
0 commit comments