fix(blog): preserve sanitized content through hydration
Deploy Canina / deploy (push) Successful in 2m12s
Deploy Canina / deploy (push) Successful in 2m12s
This commit is contained in:
1 parent
5573bb3568
commit
297aaadbe6
6 files changed
+72
-17
No files matched your search
@@ -80,6 +80,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -113,6 +114,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -133,6 +135,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -170,6 +173,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -215,6 +219,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -241,6 +246,7 @@ describe("BlogPostClient Component", () => {
|
||||
render(
|
||||
<BlogPostClient
|
||||
blog={mockBlog}
|
||||
sanitizedContent={mockBlog.content}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
@@ -254,4 +260,25 @@ describe("BlogPostClient Component", () => {
|
||||
expect(screen.getByText("لینک کپی شد!")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("renders the server-sanitized article HTML instead of recomputing content in the browser", () => {
|
||||
const rawContent = "<!--metaTitle: hidden--><p>متن خام متفاوت</p><script>alert(1)</script>";
|
||||
const sanitizedContent = "<p>اگر بچهگربهای یتیم پیدا کردهاید</p><h2>راهنمای تغذیه</h2>";
|
||||
|
||||
const { container } = render(
|
||||
<BlogPostClient
|
||||
blog={{ ...mockBlog, content: rawContent }}
|
||||
sanitizedContent={sanitizedContent}
|
||||
publishedDate="۱۵ فروردین ۱۴۰۵"
|
||||
authorName="دکتر توماس بکر"
|
||||
/>
|
||||
);
|
||||
|
||||
const article = container.querySelector('.article-html-content');
|
||||
expect(article?.innerHTML).toBe(sanitizedContent);
|
||||
expect(article).toHaveTextContent('اگر بچهگربهای یتیم پیدا کردهاید');
|
||||
expect(article?.innerHTML).not.toContain('metaTitle');
|
||||
expect(article?.innerHTML).not.toContain('<script');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user