diff --git a/craft/src/components/basic/Logo.tsx b/craft/src/components/basic/Logo.tsx index 984a01a..1442e79 100644 --- a/craft/src/components/basic/Logo.tsx +++ b/craft/src/components/basic/Logo.tsx @@ -2,6 +2,7 @@ import React, { CSSProperties, useCallback, useRef, useState } from 'react'; import { useNode, UserComponent } from '@craftjs/core'; import { cssPropsToString } from '../../utils/style-helpers'; import { useSiteDesign } from '../../state/SiteDesignContext'; +import { escapeHtml, escapeAttr } from '../../utils/escape'; /* ---------- Types ---------- */ @@ -37,12 +38,6 @@ async function uploadToWhp(file: File): Promise { } catch { return null; } } -/* ---------- Helper: escape HTML ---------- */ -function esc(str: any): string { - str = String(str ?? ""); - return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); -} - /* ---------- Component ---------- */ export const Logo: UserComponent = ({ @@ -394,7 +389,7 @@ Logo.craft = { let innerHtml: string; if (props.type === 'image' && props.imageSrc) { const imgStyle = cssPropsToString({ width: props.imageWidth || '120px', height: 'auto', display: 'block' }); - innerHtml = `${esc(props.text || 'Logo')}`; + innerHtml = `${escapeAttr(props.text || 'Logo')}`; } else { const spanStyle = cssPropsToString({ fontWeight: props.fontWeight || '700', @@ -402,7 +397,7 @@ Logo.craft = { fontFamily: props.fontFamily || 'Inter, sans-serif', color: props.color || '#1f2937', }); - innerHtml = `${esc(props.text || 'MySite')}`; + innerHtml = `${escapeHtml(props.text || 'MySite')}`; } const aStyle = cssPropsToString({ @@ -414,6 +409,6 @@ Logo.craft = { }); return { - html: `${innerHtml}`, + html: `${innerHtml}`, }; }; diff --git a/craft/src/components/basic/Menu.tsx b/craft/src/components/basic/Menu.tsx index 5963187..aad7af3 100644 --- a/craft/src/components/basic/Menu.tsx +++ b/craft/src/components/basic/Menu.tsx @@ -2,6 +2,7 @@ import React, { CSSProperties, useState } from 'react'; import { useNode, UserComponent } from '@craftjs/core'; import { cssPropsToString } from '../../utils/style-helpers'; import { usePages } from '../../state/PageContext'; +import { escapeHtml, escapeAttr } from '../../utils/escape'; /* ---------- Types ---------- */ @@ -34,12 +35,6 @@ const defaultLinks: MenuLink[] = [ { text: 'Contact', href: '#contact', isCta: true }, ]; -/* ---------- Helper: escape HTML ---------- */ -function esc(str: any): string { - str = String(str ?? ""); - return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); -} - /* ---------- Component ---------- */ export const Menu: UserComponent = ({ @@ -494,7 +489,7 @@ Menu.craft = { borderRadius: link.isCta ? '6px' : '0', transition: 'color 0.15s, background-color 0.15s', }); - return `${esc(link.text)}`; + return `${escapeHtml(link.text)}`; }).join('\n '); const hoverCss = `