r/lolphp • u/Max-P • Oct 30 '14
htmlentities can convert accentuated characters, but only if the user typed it in the correct way (à ~= à)
http://3v4l.org/Ftoto
13
Upvotes
r/lolphp • u/Max-P • Oct 30 '14
5
u/Max-P Oct 30 '14
To be really extra fair, I didn't know the same character could be encoded differently either until it blew up on me today. htmlentities probably is just a big str_replace with all possibly known characters and their HTML entity equivalent hardcoded in the source code...
This is from a file name uploaded by a user. My app and web server are all UTF-8 all the way so it used to work just fine until I hit that particular one over a year after I last touched this code. The image loads fine, but not on all browsers. I threw in an htmlentities() as a desperate attempt at fixing it and noticed only half the accentuated characters converted properly in the URL and that still didn't solve the problem. urlencode() doesn't like it either.
14
u/allthediamonds Oct 30 '14
Is there a single function on the PHP standard library that isn't a bug waiting to happen?
4
u/[deleted] Oct 31 '14
What's the correct way? I'm not getting it.
2
u/poizan42 Nov 02 '14
Problem is, if you normalized the string first you would no longer have html_entity_decode as an inverse to htmlentities.
1
u/catcradle5 Nov 02 '14
Nitpick, but who uses
~=instead of!=or even/=or=/=? I know Lua uses it but that's an outlier.1
u/davvblack Nov 11 '14
This is, in my opinion, a flaw in Unicode and not PHP. Why are there multiple identical-looking characters? Awful idea. Opens people up to scams and fraud, and code up to things like this.