Skip to content

Commit be71c64

Browse files
committed
change to internal escaping mechanism
1 parent 522b172 commit be71c64

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/index.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
onCleanup,
88
ParentComponent, sharedConfig, useContext
99
} from "solid-js";
10-
import { isServer, spread } from "solid-js/web";
10+
import { isServer, spread, escape } from "solid-js/web";
1111

1212
export const MetaContext = createContext<MetaContextType>();
1313

@@ -211,28 +211,18 @@ export function useHead(tagDesc: TagDescription) {
211211
}
212212
}
213213

214-
function escapeHTML(html: string) {
215-
return html.replace(/</g, "&lt;").replace(/>/g, "&gt;");
216-
}
217-
218-
function escapeString(str: any) {
219-
if (typeof str === "string") {
220-
return str.replace(/"/g, '&quot;');
221-
}
222-
return str;
223-
}
224-
225214
export function renderTags(tags: Array<TagDescription>) {
226215
return tags
227216
.map(tag => {
228217
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("");
230220
if (tag.props.children) {
231221
// Tags might contain multiple text children:
232222
// <Title>example - {myCompany}</Title>
233223
const children = Array.isArray(tag.props.children) ? tag.props.children.join("") : tag.props.children;
234224
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}>`;
236226
}
237227
return `<${tag.tag} data-sm="${tag.id}"${props}>${children}</${tag.tag}>`;
238228
}

0 commit comments

Comments
 (0)