Skip to content

Commit

Permalink
Merge pull request #2 from bitstarr/develop
Browse files Browse the repository at this point in the history
Security and a11y
  • Loading branch information
bitstarr authored Dec 1, 2020
2 parents 7923d01 + 0623238 commit bbf7ede
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'SVG Extension'
version: 1.0.1
version: 1.0.2
description: 'Inline SVG in Twig Templates'
icon: picture-o
author:
Expand Down Expand Up @@ -27,4 +27,10 @@ form:
type: text
label: Default CSS classes
validate:
required: true
required: true
removeScriptTags:
type: toggle
label: remove script tags from SVG
default: 1
validate:
type: bool
12 changes: 10 additions & 2 deletions svg-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,24 @@ protected function createHtml(string $svgString, ?string $classes): string
$svgNodeInDocument->setAttribute('class', trim(implode(' ', $classes)));
}

if ($this->config->get('plugins.svg-extension.removeScriptTags')) {
$scriptTags = $svgNodeInDocument->getElementsByTagName('script');

foreach ($scriptTags as $scriptTag) {
$scriptTag->parentNode->removeChild($scriptTag);
}
}

if ($this->options['title']) {
$attId = uniqid('icon__title--');
$titleTag = $svgDomDoc->createElement('title', $this->options['title']);
$titleTag->setAttribute('id', $attId);
$svgNodeInDocument->appendChild($titleTag);
$svgNodeInDocument->setAttribute('role', 'image');
$svgNodeInDocument->setAttribute('role', 'img');
$svgNodeInDocument->setAttribute('aria-labelledby', $attId);
}
else {
$svgNodeInDocument->setAttribute('role', 'presentation');
$svgNodeInDocument->setAttribute('role', 'img');
$svgNodeInDocument->setAttribute('aria-hidden', 'true');
}

Expand Down
3 changes: 2 additions & 1 deletion svg-extension.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
enabled: true
path: 'theme://dist/icons/'
defaultClass: 'icon'
defaultClass: 'icon'
removeScriptTags: true

0 comments on commit bbf7ede

Please sign in to comment.