Skip to content

Commit 8ffcc41

Browse files
committed
Update resource validation logic
The previous logic did not validate the font-family when set by attribute. To accommodate style validation across all sources the Style class now accepts the Document during construction so that it has access to the allowExternalReferences property regardless of style source.
1 parent 8a8a1eb commit 8ffcc41

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/Svg/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function before($attributes)
202202
{
203203
$surface = $this->getSurface();
204204

205-
$style = new DefaultStyle();
205+
$style = new DefaultStyle($this);
206206
$style->inherit($this);
207207
$style->fromAttributes($attributes);
208208

src/Svg/Style.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Style
1818
const TYPE_ANGLE = 4;
1919
const TYPE_NUMBER = 5;
2020

21+
private $_document;
2122
private $_parentStyle;
2223

2324
public $color;
@@ -43,6 +44,12 @@ class Style
4344
public $fontStyle = 'normal';
4445
public $textAnchor = 'start';
4546

47+
public function __construct($document = null) {
48+
if ($document !== null) {
49+
$this->_document = $document;
50+
}
51+
}
52+
4653
protected function getStyleMap()
4754
{
4855
return array(
@@ -139,16 +146,6 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
139146
break;
140147
}
141148
}
142-
143-
if (
144-
\array_key_exists("font-family", $styles)
145-
&& (
146-
\strtolower(\substr($this->href, 0, 7)) === "phar://"
147-
|| ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5)) !== "data:")
148-
)
149-
) {
150-
unset($style["font-family"]);
151-
}
152149
}
153150
}
154151

@@ -185,6 +182,16 @@ protected function fillStyles($styles)
185182
$value = $styles[$from];
186183
}
187184

185+
if ($from === "font-family") {
186+
$scheme = \strtolower(parse_url($value, PHP_URL_SCHEME) ?: "");
187+
if (
188+
$scheme === "phar" || \strtolower(\substr($value, 0, 7)) === "phar://"
189+
|| ($this->_document !== null && $this->_document->allowExternalReferences === false && $scheme !== "data")
190+
) {
191+
continue;
192+
}
193+
}
194+
188195
if ($value !== null) {
189196
$this->$to = $value;
190197
}

src/Svg/Tag/AbstractTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getStyle()
119119
* @return Style
120120
*/
121121
protected function makeStyle($attributes) {
122-
$style = new Style();
122+
$style = new Style($this->document);
123123
$style->inherit($this);
124124
$style->fromStyleSheets($this, $attributes);
125125
$style->fromAttributes($attributes);

src/Svg/Tag/Image.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ public function start($attributes)
5858

5959
$this->document->getSurface()->transform(1, 0, 0, -1, 0, $height);
6060

61-
if (\strtolower(\substr($this->href, 0, 7)) === "phar://" || ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5) !== "data:"))) {
62-
return;
61+
if ($from === "font-family") {
62+
$scheme = \strtolower(parse_url($this->href, PHP_URL_SCHEME) ?: "");
63+
if (
64+
$scheme === "phar" || \strtolower(\substr($this->href, 0, 7)) === "phar://"
65+
|| ($this->document->allowExternalReferences === false && $scheme !== "data")
66+
) {
67+
return;
68+
}
6369
}
6470

6571
$this->document->getSurface()->drawImage($this->href, $this->x, $this->y, $this->width, $this->height);

0 commit comments

Comments
 (0)