Skip to content

Commit 172dbf9

Browse files
committed
fix(ssr): should also escape static text content
fix #6345
1 parent f4ee63c commit 172dbf9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/server/optimizing-compiler/codegen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
applyModelTransform
2323
} from './modules'
2424

25+
import { escape } from 'web/server/util'
2526
import { optimizability } from './optimizer'
26-
2727
import type { CodegenResult } from 'compiler/codegen/index'
2828

2929
export type StringSegment = {
@@ -222,7 +222,7 @@ function nodesToSegments (
222222
} else if (c.type === 2) {
223223
segments.push({ type: INTERPOLATION, value: c.expression })
224224
} else if (c.type === 3) {
225-
segments.push({ type: RAW, value: c.text })
225+
segments.push({ type: RAW, value: escape(c.text) })
226226
}
227227
}
228228
return segments

test/ssr/ssr-string.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,15 @@ describe('SSR: renderToString', () => {
908908
done()
909909
})
910910
})
911+
912+
it('should escape static strings', done => {
913+
renderVmWithOptions(({
914+
template: `<div>&lt;foo&gt;</div>`
915+
}), res => {
916+
expect(res).toBe(`<div data-server-rendered="true">&lt;foo&gt;</div>`)
917+
done()
918+
})
919+
})
911920
})
912921

913922
function renderVmWithOptions (options, cb) {

0 commit comments

Comments
 (0)