FIX: Autoplay videos must always be muted (#11533)
This automatically adds the muted attribute if it's missing in a video tag. Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
parent
38950840e0
commit
c4552e9c10
|
@ -168,6 +168,38 @@ module("Unit | Utility | sanitizer", function () {
|
|||
);
|
||||
});
|
||||
|
||||
test("autoplay videos must be muted", function (assert) {
|
||||
let pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
assert.ok(
|
||||
pt
|
||||
.sanitize(
|
||||
`<p>Hey</p><video autoplay src="http://example.com/music.mp4"/>`
|
||||
)
|
||||
.match(/muted/)
|
||||
);
|
||||
assert.ok(
|
||||
pt
|
||||
.sanitize(
|
||||
`<p>Hey</p><video autoplay><source src="http://example.com/music.mp4" type="audio/mpeg"></video>`
|
||||
)
|
||||
.match(/muted/)
|
||||
);
|
||||
assert.ok(
|
||||
pt
|
||||
.sanitize(
|
||||
`<p>Hey</p><video autoplay muted><source src="http://example.com/music.mp4" type="audio/mpeg"></video>`
|
||||
)
|
||||
.match(/muted/)
|
||||
);
|
||||
assert.notOk(
|
||||
pt
|
||||
.sanitize(
|
||||
`<p>Hey</p><video><source src="http://example.com/music.mp4" type="audio/mpeg"></video>`
|
||||
)
|
||||
.match(/muted/)
|
||||
);
|
||||
});
|
||||
|
||||
test("poorly formed ids on headings", function (assert) {
|
||||
let pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
assert.equal(
|
||||
|
|
|
@ -225,7 +225,7 @@ export const DEFAULT_LIST = [
|
|||
"track[srclang]",
|
||||
"ul",
|
||||
"video",
|
||||
"video[autoplay]",
|
||||
// video[autoplay] handled by sanitizer.js
|
||||
"video[controls]",
|
||||
"video[controlslist]",
|
||||
"video[crossorigin]",
|
||||
|
|
|
@ -126,6 +126,12 @@ export function sanitize(text, allowLister) {
|
|||
return "-STRIP-";
|
||||
}
|
||||
|
||||
if (tag === "video" && name === "autoplay") {
|
||||
// This might give us duplicate 'muted' atttributes
|
||||
// but they will be deduped by later processing
|
||||
return "autoplay muted";
|
||||
}
|
||||
|
||||
// Heading ids must begin with `heading--`
|
||||
if (
|
||||
["h1", "h2", "h3", "h4", "h5", "h6"].indexOf(tag) !== -1 &&
|
||||
|
|
Loading…
Reference in New Issue