Skip to content

Commit 9f9bea7

Browse files
authored
Fixed Twitter/X embeds (#2022)
With the Twitter → X rebrand, the Twitter widget moved from being hosted on `platform.twitter.com` to new being hosted on `platform.x.com`. With this change, both legacy and new URLs are supported as widget hosts. Also cleaned up the unnecessary `allowedScriptDomains: ['twitter.com']`.
1 parent ee742c5 commit 9f9bea7

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/helpers/html.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ export function sanitizeHtml(content: string): string {
249249
'loop',
250250
],
251251
},
252-
allowedScriptDomains: ['twitter.com'],
253-
allowedScriptHostnames: ['platform.twitter.com'],
252+
allowedScriptHostnames: ['platform.twitter.com', 'platform.x.com'],
254253
allowVulnerableTags: true,
255254
});
256255
}

src/helpers/html.unit.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ describe('sanitizeHtml', () => {
3636
await import('sanitize-html');
3737
const { sanitizeHtml: realSanitizeHtml } = await import('./html');
3838

39-
const content =
40-
'<script src="https://bad.com/script.js"></script><script src="https://twitter.com/script.js"></script><p>Hello, world!</p>';
39+
const content = [
40+
'<script src="https://bad.com/script.js"></script>',
41+
'<script src="https://platform.twitter.com/widgets.js"></script>',
42+
'<script src="https://platform.x.com/widgets.js"></script>',
43+
'<p>Hello, world!</p>',
44+
].join('');
4145

4246
const result = realSanitizeHtml(content);
4347

4448
expect(result).toEqual(
45-
'<script></script><script src="https://twitter.com/script.js"></script><p>Hello, world!</p>',
49+
'<script></script><script src="https://platform.twitter.com/widgets.js"></script><script src="https://platform.x.com/widgets.js"></script><p>Hello, world!</p>',
4650
);
4751

4852
// Restore the mock for subsequent tests

0 commit comments

Comments
 (0)