Handle tag specialization correctly

This commit is contained in:
Jaapio
2020-02-09 09:05:22 +01:00
parent ed7b7919e3
commit 264bd1fff7
2 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -68,7 +68,7 @@ use function trim;
final class StandardTagFactory implements TagFactory final class StandardTagFactory implements TagFactory
{ {
/** PCRE regular expression matching a tag name. */ /** PCRE regular expression matching a tag name. */
public const REGEX_TAGNAME = '[\w\-\_\\\\]+'; public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';
/** /**
* @var string[] An array with a tag as a key, and an * @var string[] An array with a tag as a key, and an
@@ -194,7 +194,7 @@ final class StandardTagFactory implements TagFactory
private function extractTagParts(string $tagLine) : array private function extractTagParts(string $tagLine) : array
{ {
$matches = []; $matches = [];
if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')((?:[\s\(\{:])\s*([^\s].*)|$)/us', $tagLine, $matches)) { if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')((?:[\s\(\{])\s*([^\s].*)|$)/us', $tagLine, $matches)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
); );
@@ -372,9 +372,14 @@ class StandardTagFactoryTest extends TestCase
'@tag', '@tag',
], ],
'tag specialization' => [ 'tag specialization' => [
'@tag:some-spec', '@tag:some-spec body',
'tag', 'tag:some-spec',
'@tag :some-spec', '@tag:some-spec body',
],
'tag specialization(a)' => [
'@tag:some-spec(body)',
'tag:some-spec',
'@tag:some-spec (body)',
], ],
'tag with textual description' => [ 'tag with textual description' => [
'@tag some text', '@tag some text',