Repository navigation
fix: correct old input, validation rules, route lookups and error responses - #402
Conversation
…ponses - Restore every old() field and read array input - Count characters in min, max and size, and reject impossible dates - Match JSON numbers in in and not_in, and reject trailing newlines - Reject whitespace-only values in required - Keep the dispatched route in currentRouteAction() - Use the dispatched method in currentRouteName() - Treat _method=ANY as an invalid method - Use the fallback in back() for a blank Referer - Send exception headers on web error pages - Use only HTTP error statuses from exception codes in JSON errors - Use relations' jsonSerialize() in JSON responses when an override calls toArray() - Prefer plain text when decrypting legacy ciphertext
|
Thanks, most of this checks out. I'm requesting changes because two of the fixes don't fully cover the cases the description claims. I reproduced both against this branch. Fix before merge1.
|
- currentRouteName() no longer returns another method's name; names keep their path per method, including in the route cache - where() only moves the name of the route it constrains - StreamedJsonResponse uses a relation's jsonSerialize() when encoding models - JsonErrorHandler keeps an HttpException's headers
abdulmajidcse
left a comment
There was a problem hiding this comment.
@techmahedy All four are done in 8c6f8cd:
currentRouteName()no longer falls back to another method's name, and an attribute route keeps its name for every method. I storedname => [method => path]instead of a list of methods, because a list still gave the wrong name when a name was reused on another path. It's saved in the route cache.StreamedJsonResponsenow uses the relation'sjsonSerialize(). I wrapped only the model encoding, not all ofsendContent(), sotoArray()inside a generator still returns plain data.->where()only moves the name of the route it constrains.JsonErrorHandlerkeeps theHttpExceptionheaders.
The full suite and PHPStan pass locally.
Not changed, as they weren't in your review: is() still ignores the method, and WebErrorHandler doesn't apply the exception's headers.
techmahedy
left a comment
There was a problem hiding this comment.
Thanks @abdulmajidcse, all four are fixed in 8c6f8cd, and the tests cover each case from the review, plus attribute routes, older route caches and HEAD requests. It also merges cleanly with #401.
Pull Request Checklist
Description
This fixes a set of unrelated bugs in forms, validation, routing and responses.
Forms
old()deleted all old input on its first call, so only the first field was restored, and array fields threw aTypeError. Every field can now be read for the rest of the request, and the input is not kept for the next one.Validation
min,maxandsizecounted bytes, somax:3rejectedআমি. They now count characters.dateaccepted impossible dates such as2026-02-30.inandnot_incompared strictly, so the JSON number1did not match"1".alpha,alpha_num,alpha_dash,slug,digits,min_digits,max_digits,phone,uuid,intandnumericaccepted a trailing newline.requiredaccepted whitespace-only values.Routing
currentRouteAction()matched the route again, which forgot the dispatched route on closure routes in cached apps. Later name and middleware lookups then returnednull.currentRouteName()ignored the method, soPOST /postscould reportposts.index. Names now record their method, including in the route cache._method=ANYwas accepted as a real method and led to a 404. It is now a 400.Responses
Referermadeback()throw and ignored$fallback.Retry-After.JsonErrorHandlerused any exception code as the HTTP status, including invalid ones such as 2. It now uses only codes from 400 to 599, asWebErrorRendererdoes, and otherwise returns 500.jsonSerialize()override that called$this->toArray()made relations skip their ownjsonSerialize()in JSON responses.Encryption
decryptLegacy()could return garbage from the wrong key when it happened to be valid UTF-8. It now prefers text without control characters. The old format has no MAC, so this makes the problem much rarer but cannot rule it out.Behavior changes
old()now returnsmixedinstead of?string, so array fields return arrays.phoneno longer accepts tabs or newlines inside the number; spaces still work.requiredrejects whitespace-only values.intandnumericreject values with surrounding whitespace.ANYas its method now gets a 400.Known limits
json_encode($model)in application code can still miss a relation'sjsonSerialize()when the parent's override callstoArray(). Framework JSON responses are covered.Testing
Checklist