mirror of
https://github.com/discourse/discourse.git
synced 2025-02-26 22:33:55 +08:00
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
d6121249d3
commit
3a4bd80d8a
@ -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) {
|
test("poorly formed ids on headings", function (assert) {
|
||||||
let pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
let pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@ -225,7 +225,7 @@ export const DEFAULT_LIST = [
|
|||||||
"track[srclang]",
|
"track[srclang]",
|
||||||
"ul",
|
"ul",
|
||||||
"video",
|
"video",
|
||||||
"video[autoplay]",
|
// video[autoplay] handled by sanitizer.js
|
||||||
"video[controls]",
|
"video[controls]",
|
||||||
"video[controlslist]",
|
"video[controlslist]",
|
||||||
"video[crossorigin]",
|
"video[crossorigin]",
|
||||||
|
@ -126,6 +126,12 @@ export function sanitize(text, allowLister) {
|
|||||||
return "-STRIP-";
|
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--`
|
// Heading ids must begin with `heading--`
|
||||||
if (
|
if (
|
||||||
["h1", "h2", "h3", "h4", "h5", "h6"].indexOf(tag) !== -1 &&
|
["h1", "h2", "h3", "h4", "h5", "h6"].indexOf(tag) !== -1 &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user