Add $allowEmpty parameter to URL validator#7
Conversation
Agent-Logs-Url: https://github.com/utopia-php/validators/sessions/cce228f0-a09a-4f4c-83c5-06eebec02fe8 Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
…lidator Agent-Logs-Url: https://github.com/utopia-php/validators/sessions/cce228f0-a09a-4f4c-83c5-06eebec02fe8 Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Co-authored-by: Matej Bačo <matejbaco2000@gmail.com>
Greptile SummaryThis PR adds an Confidence Score: 3/5Not safe to merge until the A P1 inconsistency exists between the documented contract (
Important Files Changed
Reviews (1): Last reviewed commit: "Apply suggestions from code review" | Re-trigger Greptile |
The URL validator had no way to permit empty values, making it impossible to use for optional URL fields without wrapping it.
Changes
URL.php: Addedbool $allowEmpty = falseconstructor parameter. Whentrue,isValid()short-circuits totruefor''andnull. Uses strict equality (=== '',=== null) rather thanempty()to avoid false positives on'0'/0.URLTest.php: AddedtestAllowEmpty()covering empty/null pass-through, valid URL still accepted, invalid non-empty URL still rejected, and default behavior (empty disallowed).Usage