Merging upstream version 5.3.0+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
a87fc4fcc7
commit
e92720b6a7
605 changed files with 15320 additions and 9495 deletions
|
@ -1,6 +1,6 @@
|
|||
import Backdrop from '../../../src/util/backdrop'
|
||||
import { getTransitionDurationFromElement } from '../../../src/util/index'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import Backdrop from '../../../src/util/backdrop.js'
|
||||
import { getTransitionDurationFromElement } from '../../../src/util/index.js'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
const CLASS_BACKDROP = '.modal-backdrop'
|
||||
const CLASS_NAME_FADE = 'fade'
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* Test helpers */
|
||||
|
||||
import { clearFixture, createEvent, getFixture } from '../../helpers/fixture'
|
||||
import { enableDismissTrigger } from '../../../src/util/component-functions'
|
||||
import BaseComponent from '../../../src/base-component'
|
||||
import BaseComponent from '../../../src/base-component.js'
|
||||
import { enableDismissTrigger } from '../../../src/util/component-functions.js'
|
||||
import { clearFixture, createEvent, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
class DummyClass2 extends BaseComponent {
|
||||
static get NAME() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Config from '../../../src/util/config'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import Config from '../../../src/util/config.js'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
class DummyConfigClass extends Config {
|
||||
static get NAME() {
|
||||
|
@ -128,7 +128,7 @@ describe('Config', () => {
|
|||
const obj = new DummyConfigClass()
|
||||
expect(() => {
|
||||
obj._typeCheckConfig(config)
|
||||
}).toThrowError(TypeError, obj.constructor.NAME.toUpperCase() + ': Option "parent" provided type "number" but expected type "(string|element)".')
|
||||
}).toThrowError(TypeError, `${obj.constructor.NAME.toUpperCase()}: Option "parent" provided type "number" but expected type "(string|element)".`)
|
||||
})
|
||||
|
||||
it('should return null stringified when null is passed', () => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import FocusTrap from '../../../src/util/focustrap'
|
||||
import EventHandler from '../../../src/dom/event-handler'
|
||||
import SelectorEngine from '../../../src/dom/selector-engine'
|
||||
import { clearFixture, createEvent, getFixture } from '../../helpers/fixture'
|
||||
import EventHandler from '../../../src/dom/event-handler.js'
|
||||
import SelectorEngine from '../../../src/dom/selector-engine.js'
|
||||
import FocusTrap from '../../../src/util/focustrap.js'
|
||||
import { clearFixture, createEvent, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
describe('FocusTrap', () => {
|
||||
let fixtureEl
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as Util from '../../../src/util/index'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import { noop } from '../../../src/util/index'
|
||||
import * as Util from '../../../src/util/index.js'
|
||||
import { noop } from '../../../src/util/index.js'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
describe('Util', () => {
|
||||
let fixtureEl
|
||||
|
@ -22,119 +22,6 @@ describe('Util', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getSelectorFromElement', () => {
|
||||
it('should get selector from data-bs-target', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="test" data-bs-target=".target"></div>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
|
||||
})
|
||||
|
||||
it('should get selector from href if no data-bs-target set', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" href=".target"></a>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
|
||||
})
|
||||
|
||||
it('should get selector from href if data-bs-target equal to #', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" data-bs-target="#" href=".target"></a>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
|
||||
})
|
||||
|
||||
it('should return null if a selector from a href is a url without an anchor', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" data-bs-target="#" href="foo/bar.html"></a>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toBeNull()
|
||||
})
|
||||
|
||||
it('should return the anchor if a selector from a href is a url', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" data-bs-target="#" href="foo/bar.html#target"></a>',
|
||||
'<div id="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toEqual('#target')
|
||||
})
|
||||
|
||||
it('should return null if selector not found', () => {
|
||||
fixtureEl.innerHTML = '<a id="test" href=".target"></a>'
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toBeNull()
|
||||
})
|
||||
|
||||
it('should return null if no selector', () => {
|
||||
fixtureEl.innerHTML = '<div></div>'
|
||||
|
||||
const testEl = fixtureEl.querySelector('div')
|
||||
|
||||
expect(Util.getSelectorFromElement(testEl)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getElementFromSelector', () => {
|
||||
it('should get element from data-bs-target', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="test" data-bs-target=".target"></div>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getElementFromSelector(testEl)).toEqual(fixtureEl.querySelector('.target'))
|
||||
})
|
||||
|
||||
it('should get element from href if no data-bs-target set', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" href=".target"></a>',
|
||||
'<div class="target"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getElementFromSelector(testEl)).toEqual(fixtureEl.querySelector('.target'))
|
||||
})
|
||||
|
||||
it('should return null if element not found', () => {
|
||||
fixtureEl.innerHTML = '<a id="test" href=".target"></a>'
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(Util.getElementFromSelector(testEl)).toBeNull()
|
||||
})
|
||||
|
||||
it('should return null if no selector', () => {
|
||||
fixtureEl.innerHTML = '<div></div>'
|
||||
|
||||
const testEl = fixtureEl.querySelector('div')
|
||||
|
||||
expect(Util.getElementFromSelector(testEl)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTransitionDurationFromElement', () => {
|
||||
it('should get transition from element', () => {
|
||||
fixtureEl.innerHTML = '<div style="transition: all 300ms ease-out;"></div>'
|
||||
|
@ -631,6 +518,25 @@ describe('Util', () => {
|
|||
Util.execute(spy)
|
||||
expect(spy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should execute if arg is function & return the result', () => {
|
||||
const functionFoo = (num1, num2 = 10) => num1 + num2
|
||||
const resultFoo = Util.execute(functionFoo, [4, 5])
|
||||
expect(resultFoo).toBe(9)
|
||||
|
||||
const resultFoo1 = Util.execute(functionFoo, [4])
|
||||
expect(resultFoo1).toBe(14)
|
||||
|
||||
const functionBar = () => 'foo'
|
||||
const resultBar = Util.execute(functionBar)
|
||||
expect(resultBar).toBe('foo')
|
||||
})
|
||||
|
||||
it('should not execute if arg is not function & return default argument', () => {
|
||||
const foo = 'bar'
|
||||
expect(Util.execute(foo)).toBe('bar')
|
||||
expect(Util.execute(foo, [], 4)).toBe(4)
|
||||
})
|
||||
})
|
||||
|
||||
describe('executeAfterTransition', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DefaultAllowlist, sanitizeHtml } from '../../../src/util/sanitizer'
|
||||
import { DefaultAllowlist, sanitizeHtml } from '../../../src/util/sanitizer.js'
|
||||
|
||||
describe('Sanitizer', () => {
|
||||
describe('sanitizeHtml', () => {
|
||||
|
@ -10,17 +10,75 @@ describe('Sanitizer', () => {
|
|||
expect(result).toEqual(empty)
|
||||
})
|
||||
|
||||
it('should retain tags with valid URLs', () => {
|
||||
const validUrls = [
|
||||
'',
|
||||
'http://abc',
|
||||
'HTTP://abc',
|
||||
'https://abc',
|
||||
'HTTPS://abc',
|
||||
'ftp://abc',
|
||||
'FTP://abc',
|
||||
'mailto:me@example.com',
|
||||
'MAILTO:me@example.com',
|
||||
'tel:123-123-1234',
|
||||
'TEL:123-123-1234',
|
||||
'sip:me@example.com',
|
||||
'SIP:me@example.com',
|
||||
'#anchor',
|
||||
'/page1.md',
|
||||
'http://JavaScript/my.js',
|
||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/', // Truncated.
|
||||
'data:video/webm;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
'unknown-scheme:abc'
|
||||
]
|
||||
|
||||
for (const url of validUrls) {
|
||||
const template = [
|
||||
'<div>',
|
||||
` <a href="${url}">Click me</a>`,
|
||||
' <span>Some content</span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const result = sanitizeHtml(template, DefaultAllowlist, null)
|
||||
|
||||
expect(result).toContain(`href="${url}"`)
|
||||
}
|
||||
})
|
||||
|
||||
it('should sanitize template by removing tags with XSS', () => {
|
||||
const template = [
|
||||
'<div>',
|
||||
' <a href="javascript:alert(7)">Click me</a>',
|
||||
' <span>Some content</span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
const invalidUrls = [
|
||||
// eslint-disable-next-line no-script-url
|
||||
'javascript:alert(7)',
|
||||
// eslint-disable-next-line no-script-url
|
||||
'javascript:evil()',
|
||||
// eslint-disable-next-line no-script-url
|
||||
'JavaScript:abc',
|
||||
' javascript:abc',
|
||||
' \n Java\n Script:abc',
|
||||
'javascript:',
|
||||
'javascript:',
|
||||
'j avascript:',
|
||||
'javascript:',
|
||||
'javascript:',
|
||||
'jav	ascript:alert();',
|
||||
'jav\u0000ascript:alert();'
|
||||
]
|
||||
|
||||
const result = sanitizeHtml(template, DefaultAllowlist, null)
|
||||
for (const url of invalidUrls) {
|
||||
const template = [
|
||||
'<div>',
|
||||
` <a href="${url}">Click me</a>`,
|
||||
' <span>Some content</span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
expect(result).not.toContain('href="javascript:alert(7)')
|
||||
const result = sanitizeHtml(template, DefaultAllowlist, null)
|
||||
|
||||
expect(result).not.toContain(`href="${url}"`)
|
||||
}
|
||||
})
|
||||
|
||||
it('should sanitize template and work with multiple regex', () => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { clearBodyAndDocument, clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import Manipulator from '../../../src/dom/manipulator'
|
||||
import ScrollBarHelper from '../../../src/util/scrollbar'
|
||||
import Manipulator from '../../../src/dom/manipulator.js'
|
||||
import ScrollBarHelper from '../../../src/util/scrollbar.js'
|
||||
import { clearBodyAndDocument, clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
describe('ScrollBar', () => {
|
||||
let fixtureEl
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import EventHandler from '../../../src/dom/event-handler'
|
||||
import Swipe from '../../../src/util/swipe'
|
||||
import { noop } from '../../../src/util'
|
||||
import EventHandler from '../../../src/dom/event-handler.js'
|
||||
import { noop } from '../../../src/util/index.js'
|
||||
import Swipe from '../../../src/util/swipe.js'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
describe('Swipe', () => {
|
||||
const { Simulator, PointerEvent } = window
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||
import TemplateFactory from '../../../src/util/template-factory'
|
||||
import TemplateFactory from '../../../src/util/template-factory.js'
|
||||
import { clearFixture, getFixture } from '../../helpers/fixture.js'
|
||||
|
||||
describe('TemplateFactory', () => {
|
||||
let fixtureEl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue