UNPKG

@nuxtjs/mdc

Version:
40 lines (39 loc) 1.02 kB
export const unsafeLinkPrefix = [ "javascript:", "data:text/html", "vbscript:", "data:text/javascript", "data:text/vbscript", "data:text/css", "data:text/plain", "data:text/xml" ]; export const validateProp = (attribute, value) => { if (attribute.startsWith("on")) { return false; } if (attribute === "href" || attribute === "src") { return !unsafeLinkPrefix.some((prefix) => value.toLowerCase().startsWith(prefix)); } return true; }; export const validateProps = (type, props) => { if (!props) { return {}; } props = Object.fromEntries( Object.entries(props).filter(([name, value]) => { const isValid = validateProp(name, value); if (!isValid) { console.warn(`[@nuxtjs/mdc] removing unsafe attribute: ${name}="${value}"`); } return isValid; }) ); if (type === "pre") { if (typeof props.highlights === "string") { props.highlights = props.highlights.split(" ").map((i) => Number.parseInt(i)); } } return props; };