mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
move util in a util folder with the sanitizer
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
$(function () {
|
||||
'use strict'
|
||||
|
||||
QUnit.module('sanitizer', {
|
||||
afterEach: function () {
|
||||
$('#qunit-fixture').html('')
|
||||
}
|
||||
})
|
||||
|
||||
QUnit.test('should export a default white list', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
assert.ok(Sanitizer.DefaultWhitelist)
|
||||
})
|
||||
|
||||
QUnit.test('should sanitize template by removing tags with XSS', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var template = [
|
||||
'<div>',
|
||||
' <a href="javascript:alert(7)">Click me</a>',
|
||||
' <span>Some content</span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
var result = Sanitizer.sanitizeHtml(template, Sanitizer.DefaultWhitelist, null)
|
||||
|
||||
assert.strictEqual(result.indexOf('script'), -1)
|
||||
})
|
||||
|
||||
QUnit.test('should not use native api to sanitize if a custom function passed', function (assert) {
|
||||
assert.expect(2)
|
||||
|
||||
var template = [
|
||||
'<div>',
|
||||
' <span>Some content</span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
function mySanitize(htmlUnsafe) {
|
||||
return htmlUnsafe
|
||||
}
|
||||
|
||||
var spy = sinon.spy(DOMParser.prototype, 'parseFromString')
|
||||
var result = Sanitizer.sanitizeHtml(template, Sanitizer.DefaultWhitelist, mySanitize)
|
||||
|
||||
assert.strictEqual(result, template)
|
||||
assert.strictEqual(spy.called, false)
|
||||
spy.restore()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user