File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,14 @@ export function segment(
184184 : [ ...graphemeSegmenter . segment ( content ) ] . map ( ( seg ) => seg . segment )
185185}
186186
187+ function encodeAttributeValue ( value : string ) {
188+ return value
189+ . replace ( / " / g, '"' )
190+ . replace ( / < / g, '<' )
191+ . replace ( / > / g, '>' )
192+ . replace ( / & / g, '&' )
193+ }
194+
187195export function buildXMLString (
188196 type : string ,
189197 attrs : Record < string , any > ,
@@ -193,7 +201,11 @@ export function buildXMLString(
193201
194202 for ( const [ k , _v ] of Object . entries ( attrs ) ) {
195203 if ( typeof _v !== 'undefined' ) {
196- attrString += ` ${ k } ="${ _v } "`
204+ if ( typeof _v === 'string' ) {
205+ attrString += ` ${ k } ="${ encodeAttributeValue ( _v ) } "`
206+ } else {
207+ attrString += ` ${ k } ="${ _v } "`
208+ }
197209 }
198210 }
199211
You can’t perform that action at this time.
0 commit comments