Skip to content

Commit 8e4b8d6

Browse files
pi0danielroe
andcommitted
fix(ui-templates): use escapeHTML from vue
Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent c498a16 commit 8e4b8d6

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

packages/ui-templates/lib/render.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ export const RenderPlugin = () => {
9898
// Serialize into a js function
9999
const chunks = html.split(/\{{2,3}[^{}]+\}{2,3}/g).map(chunk => JSON.stringify(chunk))
100100
const hasMessages = chunks.length > 1
101+
let hasExpression = false
101102
let templateString = chunks.shift()
102103
for (const [_, expression] of html.matchAll(/\{{2,3}([^{}]+)\}{2,3}/g)) {
103104
if (expression) {
104-
templateString += ` + (${expression.trim()}) + ${chunks.shift()}`
105+
hasExpression = true
106+
templateString += ` + escapeHtml(${expression.trim()}) + ${chunks.shift()}`
105107
}
106108
}
107109
if (chunks.length > 0) {
108110
templateString += ' + ' + chunks.join(' + ')
109111
}
110112
const functionalCode = [
113+
hasExpression ? 'import { escapeHtml } from \'@vue/shared\'\n' : '',
111114
hasMessages ? `export type DefaultMessages = Record<${Object.keys({ ...genericMessages, ...messages }).map(a => `"${a}"`).join(' | ') || 'string'}, string | boolean | number >` : '',
112115
hasMessages ? `const _messages = ${JSON.stringify({ ...genericMessages, ...messages })}` : '',
113116
`export const template = (${hasMessages ? 'messages: Partial<DefaultMessages>' : ''}) => {`,

packages/ui-templates/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"devDependencies": {
2020
"@types/lodash-es": "4.17.12",
2121
"@unocss/reset": "66.0.0",
22+
"@vue/shared": "3.5.13",
2223
"beasties": "0.3.3",
2324
"html-validate": "9.5.3",
2425
"htmlnano": "2.1.1",

pnpm-lock.yaml

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy