Questions tagged [html-encode]

Anything related to encoding or decoding HTML entities.

Specifying the document's character encoding

There are several ways to specify which character encoding is used in the document. First, the web server can include the character encoding or charset in the Hypertext Transfer Protocol () Content-Type header, which would typically look like this:

Content-Type: text/html; charset=ISO-8859-1

This method gives the HTTP server a convenient way to alter document's encoding according to content negotiation; certain HTTP server software can do it, for example Apache with the module mod_charset_lite.

For HTML it is possible to include this information inside the head element near the top of the document:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

also allows the following syntax to mean exactly the same:

<meta charset="utf-8">

Character encoding in HTML: http://en.wikipedia.org/wiki/Character_encodings_in_HTML

599 questions
1516
votes
45 answers

A potentially dangerous Request.Form value was detected from the client

Every time a user posts something containing < or > in a page in my web application, I get this exception thrown. I don't want to go into the discussion about the smartness of throwing an exception or crashing an entire web application because…
Radu094
  • 26,658
  • 16
  • 56
  • 77
296
votes
4 answers

Which characters need to be escaped in HTML?

Are they the same as XML, perhaps plus the space one ( )? I've found some huge lists of HTML escape characters but I don't think they must be escaped. I want to know what needs to be escaped.
Ahmet
  • 3,550
  • 4
  • 15
  • 20
188
votes
17 answers

HtmlSpecialChars equivalent in Javascript?

Apparently, this is harder to find than I thought it would be. And it even is so simple... Is there a function equivalent to PHP's htmlspecialchars built into Javascript? I know it's fairly easy to implement that yourself, but using a built-in…
Bart van Heukelom
  • 40,403
  • 57
  • 174
  • 291
169
votes
8 answers

HtmlEncode from Class Library

I have a class library (in C#). I need to encode my data using the HtmlEncode method. This is easy to do from a web application. My question is, how do I use this method from a class library that is being called from a console application?
Villager
  • 6,221
  • 22
  • 60
  • 87
156
votes
4 answers

Transmitting newline character "\n"

Given the following URL (working, try it!) https://select-test.wp3.rbsworldpay.com/wcc/purchase?instId=151711&cartId=28524¤cy=GBP&amount=1401.49&testMode=100&name=Tom%20Gul&address=24%20House%20Road\nSome …
Tom Gullen
  • 56,187
  • 79
  • 269
  • 433
137
votes
15 answers

How do I perform HTML decoding/encoding using Python/Django?

I have a string that is HTML encoded: '''<img class="size-medium wp-image-113"\ style="margin-left: 15px;" title="su1"\ src="http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg"\ alt=""…
rksprst
  • 6,121
  • 18
  • 51
  • 79
109
votes
6 answers

How do I output raw html when using RazorEngine (NOT from MVC)

I am trying to generate emails with HTML content. this content has already gone through sanitation so I am not worried in that regard, however when I call: Razor.Parse(template, model); on the following Razor template:
KallDrexx
  • 26,119
  • 31
  • 137
  • 246
83
votes
5 answers

How to encode the plus (+) symbol in a URL

The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) signs in the email body with blank space. It looks like it only happens with the + sign. How can I remedy this? (I am working on a…
user523234
  • 12,877
  • 8
  • 55
  • 98
82
votes
5 answers

Emitting unencoded strings in a Razor view

As ScottGu says in his blog post «by default content emitted using a @ block is automatically HTML encoded to better protect against XSS attack scenarios». My question is: how can you output a non-HTML-encoded string? For the sake of simplicity, pls…
hemme
  • 1,620
  • 1
  • 15
  • 22
80
votes
6 answers

Display encoded html with razor

I store encoded HTML in the database. The only way i could display it correctly is :
@MvcHtmlString.Create(HttpUtility.HtmlDecode(Model.Content));
It's ugly. Is there any better way to do this?
jani
  • 1,325
  • 1
  • 9
  • 15
78
votes
3 answers

is there a way to highlight all the special accent characters in sublime text or any other text editor?

I a using the the HTML encode special characters in Sublime text to convert all the special character into their HTML code. I have a lot of accented characters in different parts of the file. So, it would be great if I could select all the special…
kashive
  • 1,335
  • 2
  • 11
  • 15
67
votes
9 answers

Will HTML Encoding prevent all kinds of XSS attacks?

I am not concerned about other kinds of attacks. Just want to know whether HTML Encode can prevent all kinds of XSS attacks. Is there some way to do an XSS attack even if HTML Encode is used?
Niyaz
  • 49,409
  • 55
  • 142
  • 181
66
votes
6 answers

Converting & to & etc

I want to convert & to &, " to " etc. Is there a function in c# that could do that without writing all the options manually?
user189370
59
votes
15 answers

How to remove html special chars?

I am creating a RSS feed file for my application in which I want to remove HTML tags, which is done by strip_tags. But strip_tags is not removing HTML special code chars:   & © etc. Please tell me any function which I can use to…
Prashant
  • 25,398
  • 62
  • 159
  • 219
59
votes
5 answers

How to reverse htmlentities()?

For special characters like áéí, I can call htmlentities(): $mycaption = htmlentities($mycaption, ENT_QUOTES); To get the corresponding html entities: áéí How can I reverse this back to áéí ?
Uli
  • 2,355
  • 9
  • 43
  • 67
1
2 3
39 40