|
7 | 7 | onCleanup, |
8 | 8 | ParentComponent, sharedConfig, useContext |
9 | 9 | } from "solid-js"; |
10 | | -import { isServer, spread } from "solid-js/web"; |
| 10 | +import { isServer, spread, escape } from "solid-js/web"; |
11 | 11 |
|
12 | 12 | export const MetaContext = createContext<MetaContextType>(); |
13 | 13 |
|
@@ -211,28 +211,18 @@ export function useHead(tagDesc: TagDescription) { |
211 | 211 | } |
212 | 212 | } |
213 | 213 |
|
214 | | -function escapeHTML(html: string) { |
215 | | - return html.replace(/</g, "<").replace(/>/g, ">"); |
216 | | -} |
217 | | - |
218 | | -function escapeString(str: any) { |
219 | | - if (typeof str === "string") { |
220 | | - return str.replace(/"/g, '"'); |
221 | | - } |
222 | | - return str; |
223 | | -} |
224 | | - |
225 | 214 | export function renderTags(tags: Array<TagDescription>) { |
226 | 215 | return tags |
227 | 216 | .map(tag => { |
228 | 217 | const keys = Object.keys(tag.props); |
229 | | - const props = keys.map(k => (k === "children" ? "" : ` ${k}="${escapeString(tag.props[k])}`)).join(""); |
| 218 | + // @ts-expect-error |
| 219 | + const props = keys.map(k => (k === "children" ? "" : ` ${k}="${escape(tag.props[k], true)}`)).join(""); |
230 | 220 | if (tag.props.children) { |
231 | 221 | // Tags might contain multiple text children: |
232 | 222 | // <Title>example - {myCompany}</Title> |
233 | 223 | const children = Array.isArray(tag.props.children) ? tag.props.children.join("") : tag.props.children; |
234 | 224 | if (tag.setting?.escape && typeof children === "string") { |
235 | | - return `<${tag.tag} data-sm="${tag.id}"${props}>${escapeHTML(children)}</${tag.tag}>`; |
| 225 | + return `<${tag.tag} data-sm="${tag.id}"${props}>${escape(children)}</${tag.tag}>`; |
236 | 226 | } |
237 | 227 | return `<${tag.tag} data-sm="${tag.id}"${props}>${children}</${tag.tag}>`; |
238 | 228 | } |
|
0 commit comments