[codex] Normalize null request paths during routing#232
Conversation
Greptile SummaryThis PR adds null-safety normalization around
Confidence Score: 5/5Safe to merge — targeted, correct fix with regression tests; only a minor DRY observation remains No P0 or P1 issues. The normalization logic handles all edge cases correctly (null, false, empty string, normal string paths). Both changed code paths have new regression tests. The only remaining item is a P2 DRY suggestion about duplicated logic, which does not affect correctness or reliability. No files require special attention Important Files Changed
Reviews (1): Last reviewed commit: "Normalize null request paths during rout..." | Re-trigger Greptile |
What changed
/instead of passingnullintoRouter::match().parse_url(..., PHP_URL_PATH)does not return a string.Why
Edge runs on Swoole workers, and malformed HTTP requests can arrive with a request URI whose parsed path is
null.Before this change,
Http::match()and wildcard fallback passed the raw result ofparse_url($request->getURI(), PHP_URL_PATH)directly intoRouter::match()/$route->path(...). Whenparse_url()returnednull, PHP raised aTypeErrorbecause the router expects a string path.That uncaught fatal tears down the active Swoole worker process. In edge this shows up as worker exit code
255, pod restarts, and repeated crashes under malformed traffic.This change makes the framework normalize those cases to
/, so malformed or pathless URIs degrade to a normal root-path route lookup instead of crashing the worker.Impact
Validation
vendor/bin/phpunit tests/HttpTest.php --filter "testCanMatchRootRouteWhenUriHasNoPath|testWildcardRouteWhenUriHasNoPath"vendor/bin/pint --test src/Http/Http.php tests/HttpTest.php