Skip to content

Commit

Permalink
Tests for escapeHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
chovanecm committed Jun 25, 2017
1 parent dc4e87e commit c9e3ace
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sacredboard/static/scripts/escapeHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define([], function () {
* @exports escapeHtml
*/
function replace(string) {
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
return String(string).replace(/[&<>"'`=/]/g, function (s) {
return entityMap[s];
});
}
Expand Down
4 changes: 2 additions & 2 deletions sacredboard/static/scripts/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</script>
<script src="../../vendors/require.js"></script>
<script>
require(["test_filters.js","test_dictionaryBrowser.js"],
function(filters, testDictBrowser) {
require(["test_filters.js","test_dictionaryBrowser.js", "test_escapeHtml.js"],
function(filters, testDictBrowser, testEscapeHtml) {

});
</script>
Expand Down
4 changes: 2 additions & 2 deletions sacredboard/static/scripts/tests/node_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requirejs.config({
/*eslint no-unused-vars: "off"*/ //Disable warnings of unused variables
// List all test modules to here:

requirejs(["./tests/test_filters", "./tests/test_dictionaryBrowser"],
function (filters, testDictBrowser) {
requirejs(["./tests/test_filters", "./tests/test_dictionaryBrowser", "./tests/test_escapeHtml"],
function (filters, testDictBrowser, testEscapeHtml) {
//empty, the tests get executed automatically
});
33 changes: 33 additions & 0 deletions sacredboard/static/scripts/tests/test_escapeHtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*global QUnit*/ //for eslint to ignore missing QUnit
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"'": "&#39;",
"/": "&#x2F;",
"`": "&#x60;",
"=": "&#x3D;"
};

define(["escapeHtml"], function (replace) {
QUnit.module("EscapeHTML");

QUnit.test("Test escaping &, <,>",
function (assert) {
assert.equal(replace("hello&<>world"),
"hello" + entityMap["&"] + entityMap["<"] + entityMap[">"] + "world");
});

QUnit.test("Test escaping \", ', /",
function (assert) {
assert.equal(replace("hello\"world'/"),
"hello" + entityMap["\""] + "world" + entityMap["'"] + entityMap["/"]);
});

QUnit.test("Test escaping ` and =",
function (assert) {
assert.equal(replace("hello`world="),
"hello" + entityMap["`"] + "world" + entityMap["="]);
});
});

0 comments on commit c9e3ace

Please sign in to comment.