Skip to content

Commit

Permalink
fix(ssr): should also escape static text content
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and 张祥闰 committed Sep 5, 2017
1 parent 90323b1 commit 0a1653a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/optimizing-compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
applyModelTransform
} from './modules'

import { escape } from 'web/server/util'
import { optimizability } from './optimizer'

import type { CodegenResult } from 'compiler/codegen/index'

export type StringSegment = {
Expand Down Expand Up @@ -222,7 +222,7 @@ function nodesToSegments (
} else if (c.type === 2) {
segments.push({ type: INTERPOLATION, value: c.expression })
} else if (c.type === 3) {
segments.push({ type: RAW, value: c.text })
segments.push({ type: RAW, value: escape(c.text) })
}
}
return segments
Expand Down
9 changes: 9 additions & 0 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,15 @@ describe('SSR: renderToString', () => {
done()
})
})

it('should escape static strings', done => {
renderVmWithOptions(({
template: `<div>&lt;foo&gt;</div>`
}), res => {
expect(res).toBe(`<div data-server-rendered="true">&lt;foo&gt;</div>`)
done()
})
})
})

function renderVmWithOptions (options, cb) {
Expand Down

0 comments on commit 0a1653a

Please sign in to comment.