Prevent ChainableUndefined from testing as escaped - #2259
Open
MatMoore wants to merge 1 commit into
Open
Conversation
MatMoore
marked this pull request as ready for review
September 1, 2026 15:47
davidism
reviewed
Sep 1, 2026
| def test_escaped(value: t.Any) -> bool: | ||
| """Check if the value is escaped.""" | ||
| return hasattr(value, "__html__") | ||
| return hasattr(value, "__html__") and not isinstance(value, ChainableUndefined) |
Member
There was a problem hiding this comment.
Let's be safe and use the base Undefined. No undefined value should ever be considered escaped, regardless of the specifics.
Author
There was a problem hiding this comment.
No problem, have just adjusted it
Member
|
I can write a changelog, no problem. I really appreciate that you checked the contributing guide! |
The implementation of the `escaped` test uses `hasattr` to detect escaped string, but `ChainableUndefined` returns self for any attribute, so `hasattr` always returns True. This means the test returned true for `ChainableUndefined` even though other Undefined values correctly returned false.
MatMoore
force-pushed
the
is-escaped-should-fail-for-chainable-undefined
branch
from
September 2, 2026 08:34
5460156 to
76c223f
Compare
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.
fixes #2244
The implementation of the
escapedtest useshasattrto detect escaped strings, butChainableUndefinedreturnsselffor any attribute, sohasattralways returns True.This means the
value is escapedtest returned true forChainableUndefinedeven though other Undefined values correctly returned false.I don't think any documentation needs updating, but please correct me if I'm wrong. The contributing guide said adding a changelog is optional, and I wasn't sure how to do it, so I've left that out.