-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow bool $doubleEncode optional param to escapeHtml() #54
Conversation
Allows $double_encode to be sent to htmlspecialchars(). This is a non-breaking change. Signed-off-by: objecttothis <[email protected]>
Signed-off-by: objecttothis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current behavior in html context causes
& &
to be encoded as&amp; &
.htmlspecialchars()
has a fourth optional parameterbool $double_encode = true
, so by default it's double encoding.
I don't think we should do this at all: & &
being encoded as &amp; &
is expected behavior.
I wouldn't put my fire on laminas-escaper being fully bi-directional as it is, but we should strive for it.
$string === decode(encode($string))
is what we should kinda have, at logical constraint.
To be clear, encoding is a bi-directional process: you encode and de-code. The fact that you skip re-encoding means that decoding will lead to invalid conversions, breaking this bidirectionality. |
Why does PHP offer this exact functionality in htmlspecialchars() and htmlentities() if not for this exact situation where double encoding breaks decoding? |
PHP is full of quirks and bad ideas: it's not a good design reference, but it cannot easily remove arguments, once they are introduced, mostly for backwards compatibility. I traced back the last time this argument handling was refactored (not introduced: it's likely much older) to ~14y ago in php/php-src@91727cb Be aware that these php-src arguments were already present when this Laminas component was designed. |
This is what I have in my workaround code. It's problem is that it either html encodes the entire string or none at all. I think I understand your argument for bi-directionality of laminas-escaper in all aspects to mean that with my addition
$sameThing would be false because the result of the decode would be Please humor me for a moment. Imagine I'm you before you learned that it was bad practice and explain why it's bad design in this context: I have Now if I don't have $double_encode (as is the case with current |
The user sees the text Your content is either text (and should be escaped), or it is HTML for which you'd heavily sanitize before keeping anything as-is. Anything in-between is not part of this component: it's a wasteland that nobody should traverse :-) |
Allows $doubleEncode to be sent to htmlspecialchars() in html context.
Description
Tell us about why this change is necessary: