# extendify/3.0.4/src/Shared/utils/__tests__/sanitize.test.js

Extendify, version 3.0.4. 33 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.0.4/code/src/Shared/utils/__tests__/sanitize.test.js
- Raw: https://pluginprobe.com/plugins/extendify/3.0.4/raw/src/Shared/utils/__tests__/sanitize.test.js
- Modified: 2025-03-13T17:10:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.0.4/code/src/Shared/utils/__tests__/sanitize.test.js#L10-L20`.

```javascript
import { sanitizeString } from '@shared/utils/sanitize';

describe('sanitizeString', () => {
	it('should return an empty string if input is null or undefined', () => {
		expect(sanitizeString(null)).toBe('');
		expect(sanitizeString(undefined)).toBe('');
		expect(sanitizeString('')).toBe('');
	});

	it('should not modify safe HTML content', () => {
		const safeHtml = '<p>Hello, <b>World</b>!</p>';
		expect(sanitizeString(safeHtml)).toBe(safeHtml);
	});

	it('should remove disallowed HTML tags', () => {
		const dirtyHtml = '<script>alert("XSS")</script><p>Secure text</p>';
		expect(sanitizeString(dirtyHtml)).toBe('alert("XSS")<p>Secure text</p>');
	});

	it('should remove multiple disallowed tags', () => {
		const dirtyHtml =
			'<iframe src="http://malicious.com"></iframe><meta><style>body{background:red;}</style><p>Ok</p>';
		expect(sanitizeString(dirtyHtml)).toBe('body{background:red;}<p>Ok</p>');
	});

	it('should remove JavaScript URLs', () => {
		const dirtyHtml = '<a href="javascript:alert(\'XSS\')">Click here</a>';
		expect(sanitizeString(dirtyHtml)).toBe(
			'<a href="alert(\'XSS\')">Click here</a>',
		);
	});
});

```
