diff --git a/bridge/src/lib/sanitize-html.test.ts b/bridge/src/lib/sanitize-html.test.ts new file mode 100644 index 0000000..5d43793 --- /dev/null +++ b/bridge/src/lib/sanitize-html.test.ts @@ -0,0 +1,184 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { sanitize_article_html } from '../lib/sanitize-html.js'; + +test('strips script tags from article content', () => { + const input = '
Hello
World
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Hello
World
'); +}); + +test('strips script tags with attributes', () => { + const input = 'Text
More
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
More
'); +}); + +test('strips script tags with type attribute', () => { + const input = 'Text
More
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
More
'); +}); + +test('strips multiple script tags', () => { + const input = 'A
B
'; + const result = sanitize_article_html(input); + assert.equal(result, 'A
B
'); +}); + +test('strips script with multiline content', () => { + const input = 'Before
After
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Before
After
'); +}); + +test('strips script with nested angle brackets (inline JSON)', () => { + const input = 'Text
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
'); +}); + +test('strips style tags from article content', () => { + const input = 'Text
More
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
More
'); +}); + +test('strips style tags with attributes', () => { + const input = 'Text
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
'); +}); + +test('strips link tags from article content', () => { + const input = 'Text
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
'); +}); + +test('strips multiple link tags', () => { + const input = 'Text
'; + const result = sanitize_article_html(input); + assert.equal(result, 'Text
'); +}); + +test('strips inline event handlers', () => { + const input = '
";
+ const result = sanitize_article_html(input);
+ assert.ok(!result.includes('onerror'), `Expected no onerror in: ${result}`);
+});
+
+test('strips inline event handlers with unquoted values', () => {
+ const input = '