feat(embeds): add extensible embed registry, universal plugin, and pair-aware sanitizer

This commit is contained in:
Jakub Zych
2026-11-28 12:49:35 +01:00
parent 4c3f9b4568
commit babd3a95b9
6 changed files with 482 additions and 75 deletions

View File

@@ -82,8 +82,8 @@ test('a placeholder smuggling an iframe or extra attributes expands only its val
})
test('a malformed placeholder stays an empty figure after the sink', () => {
assert.equal(sink(`<figure data-embed="youtube" data-id="short"></figure>`), '<figure data-embed="youtube"></figure>')
assert.equal(sink(`<figure data-embed="vimeo" data-id="${ID}"></figure>`), `<figure data-id="${ID}"></figure>`)
assert.equal(sink(`<figure data-embed="youtube" data-id="short"></figure>`), '<figure></figure>')
assert.equal(sink(`<figure data-embed="vimeo" data-id="${ID}"></figure>`), '<figure></figure>')
assert.equal(iframeCount(sink(`<figure data-embed="vimeo" data-id="${ID}"></figure>`)), 0)
})

View File

@@ -247,10 +247,10 @@ test('the embed placeholder survives two sanitizer passes (payload, then sink)',
test('embed attributes outside the four editor rules are still stripped', () => {
const cases: Array<[string, string, string]> = [
['other provider', '<figure data-embed="vimeo" data-id="dQw4w9WgXcQ"></figure>', '<figure data-id="dQw4w9WgXcQ"></figure>'],
['10-character id', '<figure data-embed="youtube" data-id="dQw4w9WgXc"></figure>', '<figure data-embed="youtube"></figure>'],
['12-character id', '<figure data-embed="youtube" data-id="dQw4w9WgXcQQ"></figure>', '<figure data-embed="youtube"></figure>'],
['id with a quote', '<figure data-embed="youtube" data-id="dQw4w9WgX&quot;Q"></figure>', '<figure data-embed="youtube"></figure>'],
['other provider', '<figure data-embed="vimeo" data-id="dQw4w9WgXcQ"></figure>', '<figure></figure>'],
['10-character id', '<figure data-embed="youtube" data-id="dQw4w9WgXc"></figure>', '<figure></figure>'],
['12-character id', '<figure data-embed="youtube" data-id="dQw4w9WgXcQQ"></figure>', '<figure></figure>'],
['id with a quote', '<figure data-embed="youtube" data-id="dQw4w9WgX&quot;Q"></figure>', '<figure></figure>'],
['data-id on div', '<div data-embed="youtube" data-id="dQw4w9WgXcQ">x</div>', '<div>x</div>'],
['data-id on img', '<img src="/a.jpg" data-id="dQw4w9WgXcQ" />', '<img src="/a.jpg" />'],
['other data attribute on figure', '<figure data-embed="youtube" data-id="dQw4w9WgXcQ" data-src="https://evil.test/"></figure>', PLACEHOLDER],
@@ -308,11 +308,11 @@ test('the four editor rules accept exactly the editor values (D-05 amended mirro
test('the Go policy negatives are stripped the same way here', () => {
const cases: Array<[string, string, string]> = [
['upper-case provider', '<figure data-embed="YouTube" data-id="dQw4w9WgXcQ"></figure>', '<figure data-id="dQw4w9WgXcQ"></figure>'],
['provider with a suffix', '<figure data-embed="youtube2" data-id="dQw4w9WgXcQ"></figure>', '<figure data-id="dQw4w9WgXcQ"></figure>'],
['empty id', '<figure data-embed="youtube" data-id=""></figure>', '<figure data-embed="youtube"></figure>'],
['id with a URL', '<figure data-embed="youtube" data-id="javascript:1"></figure>', '<figure data-embed="youtube"></figure>'],
['id with a space', '<figure data-embed="youtube" data-id="dQw4w9 gXcQ"></figure>', '<figure data-embed="youtube"></figure>'],
['upper-case provider', '<figure data-embed="YouTube" data-id="dQw4w9WgXcQ"></figure>', '<figure></figure>'],
['provider with a suffix', '<figure data-embed="youtube2" data-id="dQw4w9WgXcQ"></figure>', '<figure></figure>'],
['empty id', '<figure data-embed="youtube" data-id=""></figure>', '<figure></figure>'],
['id with a URL', '<figure data-embed="youtube" data-id="javascript:1"></figure>', '<figure></figure>'],
['id with a space', '<figure data-embed="youtube" data-id="dQw4w9 gXcQ"></figure>', '<figure></figure>'],
['embed attributes on p', '<p data-embed="youtube" data-id="dQw4w9WgXcQ">x</p>', '<p>x</p>'],
['embed attributes on a', '<a href="/x" data-embed="youtube" data-id="dQw4w9WgXcQ">x</a>', '<a href="/x">x</a>'],
['data attribute alone on figure', '<figure data-url="https://evil.test/"></figure>', '<figure></figure>'],