Skip to content

Instantly share code, notes, and snippets.

@yoko
Created November 4, 2009 06:58
Show Gist options
  • Save yoko/225875 to your computer and use it in GitHub Desktop.
Save yoko/225875 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>String.prototype.escapeTag</title>
<link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css"/>
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<script type="text/javascript" src="String.prototype.escapeTag.js"></script>
</head>
<body>
<h1 id="qunit-header">String.prototype.escapeTag</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<script type="text/javascript">
module('String.prototype.escapeTag');
test('escapeTag', 1, function() {
equals(
'<a href="index.html?foo=foo&bar=bar">test</a>'.escapeTag(),
'&lt;a href=&quot;index.html?foo=foo&amp;bar=bar&quot;&gt;test&lt;/a&gt;'
);
});
</script>
</body>
</html>
String.prototype.escapeTag = function() {
return this.toString()
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment