There was an error while loading. Please reload this page.
1 parent 04cd91e commit bb05a71Copy full SHA for bb05a71
1 file changed
src/utils.ts
@@ -184,6 +184,14 @@ export function segment(
184
: [...graphemeSegmenter.segment(content)].map((seg) => seg.segment)
185
}
186
187
+function encodeAttributeValue(value: string) {
188
+ return value
189
+ .replace(/"/g, '"')
190
+ .replace(/</g, '<')
191
+ .replace(/>/g, '>')
192
+ .replace(/&/g, '&')
193
+}
194
+
195
export function buildXMLString(
196
type: string,
197
attrs: Record<string, any>,
@@ -193,7 +201,11 @@ export function buildXMLString(
201
202
for (const [k, _v] of Object.entries(attrs)) {
203
if (typeof _v !== 'undefined') {
- attrString += ` ${k}="${_v}"`
204
+ if (typeof _v === 'string') {
205
+ attrString += ` ${k}="${encodeAttributeValue(_v)}"`
206
+ } else {
207
+ attrString += ` ${k}="${_v}"`
208
+ }
209
198
210
199
211
0 commit comments