escapeMarkup-tests.js 954 B

123456789101112131415161718192021222324252627282930313233343536
  1. module('Utils - escapeMarkup');
  2. var Utils = require('select2/utils');
  3. test('text passes through', function (assert) {
  4. var text = 'testing this';
  5. var escaped = Utils.escapeMarkup(text);
  6. assert.equal(text, escaped);
  7. });
  8. test('html tags are escaped', function (assert) {
  9. var text = '<script>alert("bad");</script>';
  10. var escaped = Utils.escapeMarkup(text);
  11. assert.notEqual(text, escaped);
  12. assert.equal(escaped.indexOf('<script>'), -1);
  13. });
  14. test('quotes are killed as well', function (assert) {
  15. var text = 'testin\' these "quotes"';
  16. var escaped = Utils.escapeMarkup(text);
  17. assert.notEqual(text, escaped);
  18. assert.equal(escaped.indexOf('\''), -1);
  19. assert.equal(escaped.indexOf('"'), -1);
  20. });
  21. test('DocumentFragment options pass through', function (assert) {
  22. var frag = document.createDocumentFragment();
  23. frag.innerHTML = '<strong>test</strong>';
  24. var escaped = Utils.escapeMarkup(frag);
  25. assert.equal(frag, escaped);
  26. });