File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -237,12 +237,18 @@ <h2>Base64 Image Tag:</h2>
237237 downloadLink . style . display = 'none' ;
238238 fileSizeSpan . textContent = '' ;
239239
240- // Find the <?xml tag and ignore everything before it
241- const xmlIndex = svgContent . indexOf ( '<?xml' ) ;
242- if ( xmlIndex !== - 1 ) {
243- svgContent = svgContent . substring ( xmlIndex ) ;
240+ // Extract the SVG element, ignoring any surrounding content
241+ const lowerContent = svgContent . toLowerCase ( ) ;
242+ const svgStart = lowerContent . indexOf ( '<svg' ) ;
243+ const svgEnd = lowerContent . lastIndexOf ( '</svg>' ) ;
244+
245+ if ( svgStart === - 1 || svgEnd === - 1 ) {
246+ alert ( 'Invalid SVG input' ) ;
247+ return ;
244248 }
245249
250+ svgContent = svgContent . slice ( svgStart , svgEnd + '</svg>' . length ) ;
251+
246252 // Create a temporary SVG element
247253 const svgElement = new DOMParser ( ) . parseFromString ( svgContent , 'image/svg+xml' ) . documentElement ;
248254
You can’t perform that action at this time.
0 commit comments