Skip to content

Commit d4960eb

Browse files
stephenoldhamtehwave
authored andcommitted
Updated attribute regex to enable use of period and colon characters
1 parent 3bd53cc commit d4960eb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Compiler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ protected static function shortcodeRegex(string $tag): string
8181
public static function resolveAttributes(string $attributesText): ?array
8282
{
8383
$attributesText = preg_replace("/[\x{00a0}\x{200b}]+/u", ' ', $attributesText);
84-
84+
8585
$attributes = collect([]);
86-
86+
8787
if (preg_match_all(static::attributeRegex(), $attributesText, $matches, PREG_SET_ORDER)) {
8888
foreach ($matches as $match) {
8989
if (! empty($match[1])) {
@@ -100,13 +100,13 @@ public static function resolveAttributes(string $attributesText): ?array
100100
$attributes[] = stripcslashes($match[9]);
101101
}
102102
}
103-
103+
104104
// Reject any unclosed HTML elements.
105105
$filteredAttributes = $attributes->filter(function ($attribute) {
106106
if (strpos($attribute, '<') === false) {
107107
return true;
108108
}
109-
109+
110110
return preg_match('/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $attribute);
111111
});
112112

@@ -127,6 +127,6 @@ public static function resolveAttributes(string $attributesText): ?array
127127
*/
128128
protected static function attributeRegex(): string
129129
{
130-
return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
130+
return '/([\w.:-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w.:-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w.:-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|\'([^\']*)\'(?:\s|$)|(\S+)(?:\s|$)/';
131131
}
132132
}

src/Shortcode.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ abstract class Shortcode
3131
*/
3232
protected $tag;
3333

34+
/**
35+
* Optional closing tag to match in content.
36+
*
37+
* @var string
38+
*/
39+
protected $closingTag;
40+
3441
/**
3542
* The shortcode's body content.
3643
*
@@ -235,7 +242,7 @@ public function getCasts()
235242
}
236243

237244
/**
238-
* Get an attribute from the model.
245+
* Get an attribute from the class.
239246
*
240247
* @param string $key
241248
* @return mixed

tests/ShortcodeTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ public function testShortcodeAttributesCasting(): void
233233
{
234234
collect([
235235
'[cast_boolean test-boolean]' => 'true',
236+
// '[cast_boolean test-boolean="true"]' => 'true',
236237
'[cast_boolean test-boolean="1"]' => 'true',
238+
// '[cast_boolean test-boolean="false"]' => 'false',
237239
'[cast_boolean test-boolean="0"]' => 'false',
238240
'[cast_boolean /]' => 'false',
239241
'[cast_date test-date="2023-06-29"]' => (string) Date::parse('2023-06-29')->timestamp,

0 commit comments

Comments
 (0)