2019-08-08 04:16:45 +03:00
|
|
|
QUnit.module('Utils - escapeMarkup');
|
2015-01-29 16:41:18 +03:00
|
|
|
|
|
|
|
var Utils = require('select2/utils');
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('text passes through', function (assert) {
|
2015-01-29 16:41:18 +03:00
|
|
|
var text = 'testing this';
|
|
|
|
var escaped = Utils.escapeMarkup(text);
|
|
|
|
|
|
|
|
assert.equal(text, escaped);
|
|
|
|
});
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('html tags are escaped', function (assert) {
|
2015-01-29 16:41:18 +03:00
|
|
|
var text = '<script>alert("bad");</script>';
|
|
|
|
var escaped = Utils.escapeMarkup(text);
|
|
|
|
|
|
|
|
assert.notEqual(text, escaped);
|
|
|
|
assert.equal(escaped.indexOf('<script>'), -1);
|
|
|
|
});
|
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('quotes are killed as well', function (assert) {
|
2015-01-29 16:41:18 +03:00
|
|
|
var text = 'testin\' these "quotes"';
|
|
|
|
var escaped = Utils.escapeMarkup(text);
|
|
|
|
|
|
|
|
assert.notEqual(text, escaped);
|
|
|
|
assert.equal(escaped.indexOf('\''), -1);
|
|
|
|
assert.equal(escaped.indexOf('"'), -1);
|
|
|
|
});
|
2015-02-07 03:45:10 +03:00
|
|
|
|
2019-08-08 04:16:45 +03:00
|
|
|
QUnit.test('DocumentFragment options pass through', function (assert) {
|
2015-02-07 03:45:10 +03:00
|
|
|
var frag = document.createDocumentFragment();
|
|
|
|
frag.innerHTML = '<strong>test</strong>';
|
|
|
|
|
|
|
|
var escaped = Utils.escapeMarkup(frag);
|
|
|
|
|
|
|
|
assert.equal(frag, escaped);
|
|
|
|
});
|