Repository navigation
Fix #3076 - Handle None object before HTML escaping - #3078
Conversation
|
Thanks for working on a fix! I don't think this will work as expected, we don't want a passed None to appear in the output as stringified "None". Better to skip the escape() call if it's not a string. |
|
Also, looks like a few new tests are needed 😁 |
|
Hi, You are right, also tought about this solution afterwards, string casting might have other side-effect. It's effectivelly more clean to skip the escape on None values. Will come back with an update. |
|
Here it is. Ready to run tests again @birkenfeld . |
2bndy5
left a comment
There was a problem hiding this comment.
Just to be painfully clear:
An empty string is not identical to a None type.
>>> any_str = ""
>>> True if any_str else False
False
>>> True if any_str is not None else False
True>>> no_val = None
>>> True if no_val else False
False
>>> True if no_val is not None else False
FalseI'm not sure if this bears any significance in the usage here. But the issue you're trying to solve is a dynamic typing problem. It makes sense to be stricter with your type checking, no?
|
It doesn't make sense to gratuitously break people's code, no. |
|
Hi @2bndy5 , That's right, an empty string is not the same as a The important point here is to not let We might force the type checking but it would change nothing. Let's see that as avoiding useless code treatment and performance optimization 🙂 . |
|
Just to be clear, it's people passing in So we can test this in isolation. Eventually, we can even add strong types to it ( |
|
Using a blanket I agree that treating # ensure `html.escape()` is only processed when needed by the interpreter
self.filename = _filename if not _filename else html.escape(_filename)
# interpreter stops at `else` when it is None or an empty stringI'm not trying to block anything up here. I'm only trying to be helpful. |
|
Thanks all for your help and discussion. I will try to offer a new version asap. |
|
No problem, and thank you for actually contributing instead of letting Claude run wild. It's a breath of fresh air these days 🤣 |
|
Here is an update, with trivial unit tests this time. Also I discovered another clean-up code to do in (@birkenfeld, I understand you, thinking the same. Claude is like a colleague, helpful to ask a question sometimes, but not here to do the job for you :) ). Any comment is welcome. |
|
Looks good to me. This will go into a 2.20.1 release, thanks again! Also good catch on the |
Update #3078 - Force any non-NoneType to string
My proposal to fix issue #3076.
Handle None object before HTML escaping regarding commit 0f97e7c.
Various text-only attributes using
html.escapemay also be NoneType objects, which seems not to be supported byhtml.escapewhich uses built-inreplacefunction.Handling None object will avoid further of this kind of error.
Fixes #3076.