Skip to content

Commit 88163cb

Browse files
committed
Prevent circular reference in use elements
1 parent 4b43073 commit 88163cb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Svg/Tag/UseTag.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ class UseTag extends AbstractTag
1414
protected $y = 0;
1515
protected $width;
1616
protected $height;
17+
protected $instances = 0;
1718

1819
/** @var AbstractTag */
1920
protected $reference;
2021

2122
protected function before($attributes)
2223
{
24+
$this->instances++;
25+
if ($this->instances > 1) {
26+
//TODO: log circular reference error state
27+
return;
28+
}
29+
2330
if (isset($attributes['x'])) {
2431
$this->x = $attributes['x'];
2532
}
@@ -52,6 +59,9 @@ protected function before($attributes)
5259
}
5360

5461
protected function after() {
62+
if ($this->instances > 0) {
63+
return;
64+
}
5565
parent::after();
5666

5767
if ($this->reference) {
@@ -63,6 +73,11 @@ protected function after() {
6373

6474
public function handle($attributes)
6575
{
76+
if ($this->instances > 1) {
77+
//TODO: log circular reference error state
78+
return;
79+
}
80+
6681
parent::handle($attributes);
6782

6883
if (!$this->reference) {
@@ -87,6 +102,11 @@ public function handle($attributes)
87102

88103
public function handleEnd()
89104
{
105+
$this->instances--;
106+
if ($this->instances > 0) {
107+
return;
108+
}
109+
90110
parent::handleEnd();
91111

92112
if (!$this->reference) {

0 commit comments

Comments
 (0)