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><script></code>')
+ expect(ir.template).toContain('<code><script></code>')
+ expect(ir.template).not.toContain('<code><script></code>')
+ })
})
} 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
context.comment.push(node)
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE
} else {
- context.template += `<!--${node.content}-->`
+ context.template += `<!--${escapeHtml(node.content)}-->`
}
}
isConstantExpression,
isStaticExpression,
} from '../utils'
+import { escapeHtml } from '@vue/shared'
type TextLike = TextNode | InterpolationNode
const seen = new WeakMap<
} 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)
}
}
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({