Solved

Store HTML Code in database and retrieve it, escaping &lt; as < ...

Posted on 2011-02-16
2
720 Views
Last Modified: 2012-05-11
Hi everybody.
 
    I am saving the contents of a textarea in a database. this textarea contains HTML tags.
 
    I pass the data using the POST Method using the function encodeURIComponent(). It is stored normally as %-escaped characters, but when I get the data again from the database, tags like <strong>SOMETHING</strong> becomes &lt;strong&gt;SOMETHING&lt;/strong&gt;
 
    What can I do to show the data as it was typed?
 
Thanks,
 
Thiago.
0
Comment
Question by:icefinges
2 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 250 total points
ID: 34912641
First of all, I hope you know about security concerns such as  
http://en.wikipedia.org/wiki/Cross-site_scripting  
and
http://en.wikipedia.org/wiki/SQL_injection

Anyway, if you used encodeURIComponent() at some point, then later at some point you must use decodeURIComponent().  But, maybe you should be doing all this at the server. Are you sending the request to a Servlet ?
0
 

Author Comment

by:icefinges
ID: 34914943
I am concerned but it is part of a small CMS, therefore only authorized and responsible people should have access to it. Thanks for the advice.
 
In fact I was decoding it at the server-side, with URLDecode, but it was rising lots of problems so you have lead me to the solution. Now I encode and decode at the client-side.
 
Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Hi,      I've been learning Spring and Jersey for the past few months and to say in simple, i am pretty much impressed with these frameworks. Many developers feel it awkward to implement a RESTful Web Services with such a popular Web Application Fr…
Hi,    When I first started to learn Hibernate I found it pretty easy, but integrating it with Spring took me around 2 weeks. Not pretty cool. So I came up with the idea of writing this article which guides you simply towards the integration. NO…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video discusses moving either the default database or any database to a new volume.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now