Skip to content

Instantly share code, notes, and snippets.

@OllyHodgson
Created November 30, 2012 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OllyHodgson/4175212 to your computer and use it in GitHub Desktop.
Save OllyHodgson/4175212 to your computer and use it in GitHub Desktop.
While testing a system, we found some "interesting" HTML encoding behaviour. For a given value of "interesting", obviously.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Escaping fun!</title>
</head>
<body>
<!-- Renders as 'abcd' -->
<p>abcd<efg</p>
<!-- Renders as 'abcd<&efg' -->
<p>abcd<&efg</p>
</body>
</html>
@OllyHodgson
Copy link
Author

The first paragraph is rendered as "abcd". Presumably the browser sees everything after the less than symbol as part of an HTML tag. Put an ampersand immediately after it though, and it renders the whole paragraph to the page. I suspect it's because it knows tags cannot start with an ampersand, or sees it as an invalid entity, so outputs it as plain text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment