From 460d9038a16259f01b9420039634e518aa7eaa19 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sun, 18 May 2025 23:55:16 +0100 Subject: [PATCH] Update src/test/java/stirling/software/SPDF/utils/CustomHtmlSanitizerTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../SPDF/utils/CustomHtmlSanitizerTest.java | 67 ++++++------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/src/test/java/stirling/software/SPDF/utils/CustomHtmlSanitizerTest.java b/src/test/java/stirling/software/SPDF/utils/CustomHtmlSanitizerTest.java index 348ad1029..ad403331a 100644 --- a/src/test/java/stirling/software/SPDF/utils/CustomHtmlSanitizerTest.java +++ b/src/test/java/stirling/software/SPDF/utils/CustomHtmlSanitizerTest.java @@ -8,62 +8,39 @@ import org.junit.jupiter.api.Test; class CustomHtmlSanitizerTest { - @Test - void testSanitizeAllowsValidHtml() { - // Arrange - String validHtml = "
This is valid HTML with formatting.
"; - + @ParameterizedTest + @MethodSource("provideHtmlTestCases") + void testSanitizeHtml(String inputHtml, String[] expectedContainedTags) { // Act - String sanitizedHtml = CustomHtmlSanitizer.sanitize(validHtml); + String sanitizedHtml = CustomHtmlSanitizer.sanitize(inputHtml); // Assert - assertEquals(validHtml, sanitizedHtml); + for (String tag : expectedContainedTags) { + assertTrue(sanitizedHtml.contains(tag), tag + " should be preserved"); + } } - @Test - void testSanitizeAllowsFormattingElements() { - // Arrange - Testing Sanitizers.FORMATTING - String htmlWithFormatting = + private static StreamThis is valid HTML with formatting.
", + new String[] {"", "", ""}
+ ),
+ Arguments.of(
" Text with bold, italic, underline, "
+ "emphasis, strong, strikethrough, "
+ "strike, subscript, superscript, "
- + "teletype, code
, big, small.code
, big, small.
Blockquote
"), "Blockquote tags should be preserved"); - assertTrue(sanitizedHtml.contains(""), "UL tags should be preserved"); - assertTrue(sanitizedHtml.contains("
"), "OL tags should be preserved"); - assertTrue(sanitizedHtml.contains("
- "), "LI tags should be preserved"); + + "
", + new String[] {"
- Ordered item
", "", "
", "
", "", "
", "
- "} + ) + ); } @Test