File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,24 @@ for (const file of files) {
4848 const originalDOM = new JSDOM ( svgContent , { contentType : 'image/svg+xml' } ) ;
4949 const sanitizedDOM = new JSDOM ( cleanSVG , { contentType : 'image/svg+xml' } ) ;
5050
51+ const externalUrlPattern = / ^ ( h t t p s ? | f t p ) : \/ \/ / i;
52+ const imageElements = originalDOM . window . document . querySelectorAll ( 'image' ) ;
53+ const useElements = originalDOM . window . document . querySelectorAll ( 'use' ) ;
54+
55+ imageElements . forEach ( ( img , index ) => {
56+ const href = img . getAttribute ( 'href' ) || img . getAttribute ( 'xlink:href' ) ;
57+ if ( href && externalUrlPattern . test ( href . trim ( ) ) ) {
58+ issues . push ( `Found external URL in image element: ${ href } ` ) ;
59+ }
60+ } ) ;
61+
62+ useElements . forEach ( ( use , index ) => {
63+ const href = use . getAttribute ( 'href' ) || use . getAttribute ( 'xlink:href' ) ;
64+ if ( href && externalUrlPattern . test ( href . trim ( ) ) ) {
65+ issues . push ( `Found external URL in use element: ${ href } ` ) ;
66+ }
67+ } ) ;
68+
5169 const originalScripts = originalDOM . window . document . querySelectorAll ( 'script' ) ;
5270 const sanitizedScripts = sanitizedDOM . window . document . querySelectorAll ( 'script' ) ;
5371
You can’t perform that action at this time.
0 commit comments