PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / utils / __tests__ / sanitize.test.js

sanitize.test.js in Extendify 3.0.4, at src/Shared/utils/__tests__/sanitize.test.js

33 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { sanitizeString } from '@shared/utils/sanitize';
2
3 describe('sanitizeString', () => {
4 it('should return an empty string if input is null or undefined', () => {
5 expect(sanitizeString(null)).toBe('');
6 expect(sanitizeString(undefined)).toBe('');
7 expect(sanitizeString('')).toBe('');
8 });
9
10 it('should not modify safe HTML content', () => {
11 const safeHtml = '<p>Hello, <b>World</b>!</p>';
12 expect(sanitizeString(safeHtml)).toBe(safeHtml);
13 });
14
15 it('should remove disallowed HTML tags', () => {
16 const dirtyHtml = '<script>alert("XSS")</script><p>Secure text</p>';
17 expect(sanitizeString(dirtyHtml)).toBe('alert("XSS")<p>Secure text</p>');
18 });
19
20 it('should remove multiple disallowed tags', () => {
21 const dirtyHtml =
22 '<iframe src="http://malicious.com"></iframe><meta><style>body{background:red;}</style><p>Ok</p>';
23 expect(sanitizeString(dirtyHtml)).toBe('body{background:red;}<p>Ok</p>');
24 });
25
26 it('should remove JavaScript URLs', () => {
27 const dirtyHtml = '<a href="javascript:alert(\'XSS\')">Click here</a>';
28 expect(sanitizeString(dirtyHtml)).toBe(
29 '<a href="alert(\'XSS\')">Click here</a>',
30 );
31 });
32 });
33