Re_Backend/verify-object.ts

28 lines
1.1 KiB
TypeScript

import { sanitizeObject } from './src/utils/sanitizer';
const runTest = (name: string, input: any) => {
const output = sanitizeObject(input);
console.log(`[${name}] Input: ${JSON.stringify(input)}`);
console.log(`[${name}] Output: ${JSON.stringify(output)}`);
console.log(`[${name}] Description Empty String: ${output.description === ''}`);
console.log('---');
};
console.log('--- SYSTEM SANITIZER OBJECT TEST ---');
// Case 1: Script only (should become empty string)
runTest('Script Only', { description: "<script>alert(1)</script>" });
// Case 2: Encoded script only (should become empty string)
runTest('Encoded Script', { description: "&lt;script&gt;alert(1)&lt;/script&gt;" });
// Case 3: Script inside valid tags (should become empty string if result is just empty tags)
runTest('Script in tags', { description: "<p><script>alert(1)</script></p>" });
// Case 4: Valid text (should stay same)
runTest('Valid Text', { description: "<p>Hello World</p>" });
// Case 5: Empty tags/spaces (should become empty string)
runTest('Empty Tags', { description: "<p> &nbsp; </p>" });