|
| 1 | +import { sanitizeComments } from './sanitize-comments'; |
| 2 | + |
| 3 | +describe('sanitizeComments', () => { |
| 4 | + it('should escape special characters correctly', () => { |
| 5 | + const input = 'Comments <tag></tag>, {braces}, >= 5, < 5, `code`'; |
| 6 | + const output = |
| 7 | + 'Comments \\<tag\\>\\</tag\\>, \\{braces\\}, \\>= 5, \\< 5, `code`'; |
| 8 | + const result = sanitizeComments(input); |
| 9 | + expect(result).toEqual(output); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should not escape blockquotes', () => { |
| 13 | + const input = '> Blockquote with <tag>'; |
| 14 | + const output = '> Blockquote with \\<tag\\>'; |
| 15 | + const result = sanitizeComments(input); |
| 16 | + expect(result).toEqual(output); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should not escape inline code', () => { |
| 20 | + const input = 'Comment with <tag> `code with <tag> and {braces}`'; |
| 21 | + const output = 'Comment with \\<tag\\> `code with <tag> and {braces}`'; |
| 22 | + const result = sanitizeComments(input); |
| 23 | + expect(result).toEqual(output); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should not escape code block', () => { |
| 27 | + const input = ` |
| 28 | +<tag> |
| 29 | +\`\`\`html |
| 30 | +<div>x</div> |
| 31 | +\`\`\``; |
| 32 | + const expectedOutput = ` |
| 33 | +\\<tag\\> |
| 34 | +\`\`\`html |
| 35 | +<div>x</div> |
| 36 | +\`\`\``; |
| 37 | + const result = sanitizeComments(input); |
| 38 | + expect(result).toEqual(expectedOutput); |
| 39 | + }); |
| 40 | +}); |
0 commit comments