From 7d472225910171e2d518d8a29fdd982b7d6e378f Mon Sep 17 00:00:00 2001 From: boban Date: Sat, 16 May 2026 01:02:37 +0200 Subject: [PATCH] fix(routing): defensive fallback, between bounds check, condition key guard --- app/Domains/Routing/Services/SmartRoutingEngine.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Domains/Routing/Services/SmartRoutingEngine.php b/app/Domains/Routing/Services/SmartRoutingEngine.php index 5929fb1..512c8c2 100644 --- a/app/Domains/Routing/Services/SmartRoutingEngine.php +++ b/app/Domains/Routing/Services/SmartRoutingEngine.php @@ -15,7 +15,7 @@ class SmartRoutingEngine } } - return $config['fallback']; + return $config['fallback'] ?? ''; } private function ruleMatches(array $rule, array $context): bool @@ -39,6 +39,10 @@ class SmartRoutingEngine private function evaluateCondition(array $condition, array $context): bool { + if (! isset($condition['field'], $condition['op'], $condition['value'])) { + return false; + } + $field = $condition['field']; $op = $condition['op']; $expected = $condition['value']; @@ -51,7 +55,7 @@ class SmartRoutingEngine 'not_in' => ! in_array($actual, (array) $expected, true), 'contains' => str_contains((string) $actual, (string) $expected), 'starts_with' => str_starts_with((string) $actual, (string) $expected), - 'between' => $actual >= $expected[0] && $actual <= $expected[1], + 'between' => is_array($expected) && count($expected) === 2 && $actual >= $expected[0] && $actual <= $expected[1], 'greater_than' => $actual > $expected, 'less_than' => $actual < $expected, default => false,