Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ export function segment(
: [...graphemeSegmenter.segment(content)].map((seg) => seg.segment)
}

function encodeAttributeValue(value: string) {
return value
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/&/g, '&amp;')
}

export function buildXMLString(
type: string,
attrs: Record<string, any>,
Expand All @@ -193,7 +201,11 @@ export function buildXMLString(

for (const [k, _v] of Object.entries(attrs)) {
if (typeof _v !== 'undefined') {
attrString += ` ${k}="${_v}"`
if (typeof _v === 'string') {
attrString += ` ${k}="${encodeAttributeValue(_v)}"`
} else {
attrString += ` ${k}="${_v}"`
}
}
}

Expand Down