Skip to content

Commit 788afda

Browse files
committed
fix: avoid user content to be used as string params (close #727)
1 parent 6f5d132 commit 788afda

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/@vuepress/bundler-vite/src/build/renderPage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export const renderPage = async ({
7575
'<!--vuepress-ssr-styles-->',
7676
renderPageStyles({ app, outputCssAsset })
7777
)
78-
.replace('<!--vuepress-ssr-app-->', pageRendered)
78+
// page content
79+
// notice that some special chars in string like `$&` would be recognized by `replace()`,
80+
// and they won't be html-escaped and will be kept as is when they are inside a code block,
81+
// so we use a replace function as the second param to avoid those potential issues
82+
.replace('<!--vuepress-ssr-app-->', () => pageRendered)
7983
// page scripts
8084
.replace(
8185
'<!--vuepress-ssr-scripts-->',

packages/@vuepress/bundler-webpack/src/build/renderPage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ export const renderPage = async ({
9494
'<!--vuepress-ssr-styles-->',
9595
renderPageStyles({ app, initialFilesMeta, pageClientFilesMeta })
9696
)
97-
.replace('<!--vuepress-ssr-app-->', pageRendered)
97+
// page content
98+
// notice that some special chars in string like `$&` would be recognized by `replace()`,
99+
// and they won't be html-escaped and will be kept as is when they are inside a code block,
100+
// so we use a replace function as the second param to avoid those potential issues
101+
.replace('<!--vuepress-ssr-app-->', () => pageRendered)
98102
// page scripts
99103
.replace(
100104
'<!--vuepress-ssr-scripts-->',

0 commit comments

Comments
 (0)