Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ describe('compiler: text transform', () => {
expect(ir.block.operation).toMatchObject([])
expect(ir.block.effect.length).toBe(1)
})

it('escapes raw static text when generating the template string', () => {
const { ir } = compileWithTextTransform('<code>&lt;script&gt;</code>')
expect(ir.template).toContain('<code>&lt;script&gt;</code>')
expect(ir.template).not.toContain('<code><script></code>')
})
})
3 changes: 2 additions & 1 deletion packages/compiler-vapor/src/transforms/transformComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@vue/compiler-dom'
import type { NodeTransform, TransformContext } from '../transform'
import { DynamicFlag } from '../ir'
import { escapeHtml } from '@vue/shared'

export const transformComment: NodeTransform = (node, context) => {
if (node.type !== NodeTypes.COMMENT) return
Expand All @@ -14,7 +15,7 @@ export const transformComment: NodeTransform = (node, context) => {
context.comment.push(node)
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE
} else {
context.template += `<!--${node.content}-->`
context.template += `<!--${escapeHtml(node.content)}-->`
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-vapor/src/transforms/transformText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isConstantExpression,
isStaticExpression,
} from '../utils'
import { escapeHtml } from '@vue/shared'

type TextLike = TextNode | InterpolationNode
const seen = new WeakMap<
Expand Down Expand Up @@ -82,7 +83,7 @@ export const transformText: NodeTransform = (node, context) => {
} else if (node.type === NodeTypes.INTERPOLATION) {
processInterpolation(context as TransformContext<InterpolationNode>)
} else if (node.type === NodeTypes.TEXT) {
context.template += node.content
context.template += escapeHtml(node.content)
}
}

Expand Down Expand Up @@ -143,7 +144,7 @@ function processTextContainer(
const literals = values.map(getLiteralExpressionValue)

if (literals.every(l => l != null)) {
context.childrenTemplate = literals.map(l => String(l))
context.childrenTemplate = literals.map(l => escapeHtml(String(l)))
} else {
context.childrenTemplate = [' ']
context.registerOperation({
Expand Down
Loading