var sanitize = require('../lib/xss');
var sanitizeHTML = sanitize.sanitizeHTML;
var sanitizeText = sanitize.sanitizeText;
var decodeText = sanitize.decodeText;
var assert = require('assert');
var failed = 0;
function doTest(s, src, expected) {
try {
assert(s(src) === expected);
} catch (e) {
failed++;
console.log("Expected '" + expected + "'");
console.log("Got '" + s(src) + "'");
}
}
function testSanitizeHTML() {
doTest(sanitizeHTML, "< script src = bad.js>blah", "[tag removed]blah[tag removed]");
doTest(sanitizeHTML, "< img src=asdf onerror='alert(\"xss\")'>", "");
doTest(sanitizeHTML, "", "");
doTest(sanitizeHTML, "");
doTest(sanitizeHTML, ">", ">");
}
function testSanitizeText() {
doTest(sanitizeText, "", "<a href="#" onerror="javascript:alert('xss')">");
doTest(sanitizeText, "<>&"ç ", "<>&"ç	");
}
function testDecode() {
doTest(decodeText, "<a href="#" onerror="javascript:alert('xss')">", "");
doTest(decodeText, "<>&"ç	", "<>&"ç ");
}
testSanitizeHTML();
testSanitizeText();
testDecode();
if (!failed)
console.log("Tests passed.");
else
console.log(""+failed, "tests failed");