Search This Blog

Thursday, April 8, 2010

How can one prevent double encoding of html entities when they are allowed in the input

Programmer Question

How can I prevent double encoding of html entities, or fix them programmatically?



I am using the encode() function from the HTML::Entities perl module to encode HTML entities in user input. The problem here is that we also allow users to input HTML entities directly and these entities end up being double encoded.



For example, a user may enter:



Stackoverflow & Perl = Awesome…



This ends up being encoded to



Stackoverflow & Perl = Awesome…



This renders in the browser as



Stackoverflow & Perl = Awesome…



We want this to render as



Stackoverflow & Perl = Awesome...



Is there a way to prevent this double encoding? Or is there a module or snippet of code that can easily correct these double encoding issues?



Any help is greatly appreciated!



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails