Fix Route handlers convert falsy values (0, False) to empty strings #572#890
Merged
Conversation
Contributor
|
Thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix route handlers converting falsy values (0, False) to empty strings (#572)
Problem
Route handlers returning
0orFalserendered as an empty string instead of'0'/'False'. Values like1andTrueworked correctly, making the behaviour inconsistent.Cause
In
_resp(fasthtml/core.py), the guardif not resp: resp=''is true for all falsy values. It's meant to catch "no response", but0andFalseare also falsy, so they were silently replaced with''before reaching thestr(resp)conversion lower down.Fix
Narrow the check to only the value that actually means "no response":
Now
0andFalsefall through toresp = str(resp)and render as'0'and'False'.Nonestill renders empty, and empty containers ((),[]) are unaffected since they were never caught by this line — they flow through the FT-rendering path as before.Testing
Closes #572.