Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escaping html inside comment tags

Tags:

html

escaping

escaping html is fine - it will remove <'s and >'s etc.

ive run into a problem where i am outputting a filename inside a comment tag eg. <!-- ${filename} -->

of course things can be bad if you dont escape, so it becomes: <!-- <c:out value="${filename}"/> -->

the problem is that if the file has "--" in the name, all the html gets screwed, since youre not allowed to have <!-- -- -->.

the standard html escape doesnt escape these dashes, and i was wondering if anyone is familiar with a simple / standard way to escape them.

like image 480
gcrain Avatar asked Nov 26 '08 05:11

gcrain


People also ask

How do you escape HTML tags in HTML?

Escape characters will always begin with the ampersand symbol (&) and end with a semicolon symbol (;). The characters in between the ampersand and semicolon make up the specific code name or number for a particular character.

How do you comment out multiple lines in HTML?

Multiline Comments You can comment multiple lines by the special beginning tag <! -- and ending tag --> placed before the first line and end of the last line as shown in the given example below.

How do you escape less than symbol in HTML?

Less Than (<): It is reserved for use in tags (as in <div></div>). Thus, this character will have this specific meaning only. To escape them in <pre> tag tag, we need to use &lt; for HTML entity name or < for HTML entity number as a replacement.


1 Answers

Definition of a HTML comment:

A comment declaration starts with <!, followed by zero or more comments, followed by >. A comment starts and ends with "--", and does not contain any occurrence of "--".

Of course the parsing of a comment is up to the browser.

Nothing strikes me as an obvious solution here, so I'd suggest you str_replace those double dashes out.

like image 124
Ray Avatar answered Oct 05 '22 23:10

Ray