feat: Add news information management module with API and database support

- Introduced new API endpoints for querying and managing news information in the CMS.
- Implemented data model for NewsInfo and NewsInfoQuery with validation.
- Created NewsInfoMapper for database interactions and corresponding XML mappings.
- Developed INewsInfoService interface and its implementation for business logic.
- Added RichTextSanitizer utility for cleaning HTML content to prevent XSS attacks.
- Created unit tests for RichTextSanitizer to ensure proper functionality.
- Updated database schema with news_info table and necessary fields, including status and module.
- Added migration scripts for setting up the news information module in the database.
- Integrated jsoup library for HTML sanitization.
This commit is contained in:
2026-07-20 14:54:15 +08:00
parent 3a6a4333dc
commit c1a7aa3532
14 changed files with 1024 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package com.ruoyi.cms.util;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class RichTextSanitizerTest {
@Test
void shouldKeepCommonRichTextAndRemoveExecutableContent() {
String source = "<h2>标题</h2><p onclick=\"alert(1)\"><strong>正文</strong></p>"
+ "<script>alert('xss')</script>"
+ "<a href=\"javascript:alert(2)\">危险链接</a>"
+ "<img src=\"https://example.com/news.png\" onerror=\"alert(3)\">";
String cleaned = RichTextSanitizer.clean(source);
assertTrue(cleaned.contains("<h2>标题</h2>"));
assertTrue(cleaned.contains("<strong>正文</strong>"));
assertTrue(cleaned.contains("https://example.com/news.png"));
assertFalse(cleaned.contains("script"));
assertFalse(cleaned.contains("alert"));
assertFalse(cleaned.contains("onclick"));
assertFalse(cleaned.contains("onerror"));
assertFalse(cleaned.contains("javascript:"));
}
@Test
void shouldTreatEditorPlaceholderAsEmpty() {
String cleaned = RichTextSanitizer.clean("<p><br></p>");
assertFalse(RichTextSanitizer.hasContent(cleaned));
assertTrue(RichTextSanitizer.hasContent("<p>有效正文</p>"));
assertTrue(RichTextSanitizer.hasContent("<img src=\"https://example.com/a.png\">"));
}
}