Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/TagEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ protected function replaceComponent(array $matches): string
protected function parseAttributes(string $attributesString): array
{
// Regex to match attributes (both static and dynamic)
$pattern = '/([:\w-]+)(?:=["\']([^"\']+)["\'])?/';
preg_match_all($pattern, $attributesString, $matches, PREG_SET_ORDER);
$pattern = '/([:\w-]+)(?:\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s"\'=<>`]+)))?/';
preg_match_all($pattern, $attributesString, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);

$attributes = [];
foreach ($matches as $match) {
$name = $match[1];
$value = $match[2] ?? true; // If no value, set it to true
$value = $match[2] ?? $match[3] ?? $match[4] ?? true; // If no value, set it to true

$name = str_replace('-', '_', $name); // Replace hyphens with underscores so that it works with properties

Expand Down
14 changes: 14 additions & 0 deletions tests/TagEngine/CustomTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public function testTagWithAttribute(): void
$this->assertSame($expected, $result);
}

public function testTagWithUnquotedAttribute(): void
{
$result = $this->tagEngine->parse('<c-class-properties test=unquoted />');

$this->assertSame('<div class="unquoted"></div>', trim($result));
}

public function testTagWithEmptyAttribute(): void
{
$result = $this->tagEngine->parse('<c-class-properties test="" />');

$this->assertSame('<div class=""></div>', trim($result));
}

/**
* Test a tag with a tailwind class
*
Expand Down