Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Feb 20, 2022
1 parent e62ae99 commit f954c3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ private function formatAttributes(string $set, $class = '', array $attributes =
}
}

if (isset($attributes['class'])) {
$attributes['class'] = str_replace('"', '"', $attributes['class']);
}

return array_merge($attributes, $this->config['attributes'], (array) ($this->sets[$set]['attributes'] ?? []));
}

Expand Down
20 changes: 20 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ public function passing_classes_as_attributes_will_override_default_classes()
$this->assertSame('custom-class', $icon->attributes()['class']);
}

/** @test */
public function classes_with_xss_are_escaped()
{
$factory = $this->prepareSets();

$icon = $factory->svg('camera', 'h-4 w-4\" onLoad=\"alert(\'XSS\')');

$this->assertSame('h-4 w-4\" onLoad=\"alert(\'XSS\')', $icon->attributes()['class']);

$icon = $factory->svg('camera', '', ['class' => 'h-4 w-4\" onLoad=\"alert(\'XSS\')']);

$this->assertSame('h-4 w-4\" onLoad=\"alert(\'XSS\')', $icon->attributes()['class']);

$factory = $this->prepareSets(['class' => 'h-4 w-4\" onLoad=\"alert(\'XSS\')']);

$icon = $factory->svg('camera');

$this->assertSame('h-4 w-4\" onLoad=\"alert(\'XSS\')', $icon->attributes()['class']);
}

/** @test */
public function icons_can_have_attributes()
{
Expand Down

0 comments on commit f954c3f

Please sign in to comment.