From 7019eaf3b8afa8b98c649465aa61e9505b65eebe Mon Sep 17 00:00:00 2001
From: robertu <4065233+robertu7@users.noreply.github.com>
Date: Thu, 6 Jun 2024 08:30:06 +0800
Subject: [PATCH] test: reorg tests
---
src/transformers/lib/rehypeSqueezeBreaks.ts | 2 +-
src/transformers/normalize-sanitize.test.ts | 124 +++++++-------
src/transformers/sanitize.test.ts | 171 +++++++++++---------
3 files changed, 159 insertions(+), 138 deletions(-)
diff --git a/src/transformers/lib/rehypeSqueezeBreaks.ts b/src/transformers/lib/rehypeSqueezeBreaks.ts
index daedaef..2ba14e6 100644
--- a/src/transformers/lib/rehypeSqueezeBreaks.ts
+++ b/src/transformers/lib/rehypeSqueezeBreaks.ts
@@ -20,7 +20,7 @@ const squeezeSoftBreaks = ({
let breakCount = 0
children.forEach((node) => {
- if (node.type !== 'element' || node.tagName !== 'br') {
+ if (!isBr(node)) {
breakCount = 0
newChildren.push(node)
return
diff --git a/src/transformers/normalize-sanitize.test.ts b/src/transformers/normalize-sanitize.test.ts
index 2dddac2..676f745 100644
--- a/src/transformers/normalize-sanitize.test.ts
+++ b/src/transformers/normalize-sanitize.test.ts
@@ -129,68 +129,6 @@ describe('Sanitize and normalize article', () => {
)
})
- test('squeeze
', () => {
- expectProcessArticleHTML(
- stripIndent`
-
1
-2
-1
2
1
2
1
1
-2
-12
-12
-1
- `, - { maxHardBreaks: 0, maxSoftBreaks: 0 }, - ) - - // max 1 soft break - expectProcessArticleHTML( - stripIndent` -1
-2
-1
2
1
2
1
1
-2
-1
2
1
2
1
-- `, - stripIndent` -1
-2
-1
-
21
-
21
-
-- `, - { maxHardBreaks: 0, maxSoftBreaks: 0 }, - ) - }) - test('squeeze and retain all empty paragraphs', () => { expectProcessArticleHTML( stripIndent` @@ -271,4 +209,66 @@ describe('Sanitize and normalize comment', () => { `, ) }) + + test('squeeze1
-2
-12
-12
-1
-
1
+2
+1
2
1
2
1
1
+2
+12
+12
+1
+ `, + { maxHardBreaks: 0, maxSoftBreaks: 0 }, + ) + + // max 1 soft break + expectProcessCommentHTML( + stripIndent` +1
+2
+1
2
1
2
1
1
+2
+1
2
1
2
1
++ `, + stripIndent` +1
+2
+1
+
21
+
21
+
++ `, + { maxHardBreaks: 0, maxSoftBreaks: 0 }, + ) + }) }) diff --git a/src/transformers/sanitize.test.ts b/src/transformers/sanitize.test.ts index a854663..4d94f59 100644 --- a/src/transformers/sanitize.test.ts +++ b/src/transformers/sanitize.test.ts @@ -48,26 +48,6 @@ describe('Sanitization: custom', () => { { maxHardBreaks: 0 }, ) - // blockquote - expectSanitizeHTML( - stripIndent` -1
+2
+12
+12
+1
+
-- `, - stripIndent` -1
-2
- -3
-
-- `, - { maxHardBreaks: 0 }, - ) - // max 1 empty paragraph expectSanitizeHTML( stripIndent` @@ -120,65 +100,25 @@ describe('Sanitization: custom', () => { ) }) - test('squeeze1
-2
-3
-
1
-2
-1
2
1
2
1
1
-2
-12
-12
-1
- `, - { maxHardBreaks: 0, maxSoftBreaks: 0 }, - ) - - // max 1 soft break - expectSanitizeHTML( - stripIndent` -1
-2
-1
2
1
2
1
1
-2
-1
2
1
2
1
-- `, +1
-2
-1
-
21
-
21
-
++ `, stripIndent` -1
+2
+ +3
+
-- `, - { maxHardBreaks: 0, maxSoftBreaks: 0 }, +1
-2
-12
-12
-1
-
++ `, + { maxHardBreaks: 0 }, ) }) @@ -258,6 +198,87 @@ describe('Sanitization: custom', () => { `, ) }) + + test('squeeze1
+2
+3
+
1
+2
+1
2
1
2
1
1
+2
+12
+12
+1
+ `, + { maxHardBreaks: 0, maxSoftBreaks: 0 }, + ) + + // max 1 soft break + expectSanitizeHTML( + stripIndent` +1
+2
+1
2
1
2
1
1
+2
+1
2
1
2
1
1
+2
+1
2
1
2
1
1
+2
+1
2
1
2
1
++ `, + stripIndent` +1
+2
+1
+
21
+
21
+
++ `, + { maxHardBreaks: 0, maxSoftBreaks: 0 }, + ) + }) }) // via https://github.com/leizongmin/js-xss/blob/master/test/test_xss.js1
+2
+12
+12
+1
+